PW Akshay

Generation

generate functionFri, 02 Dec 2022

Create a binary file with roll number, name and marks. Input a roll number and update the marks

import os from os.path import isfile def create_file(roll_no, name, marks): #Check if file exists if isfile("students.txt"): #File Exists with open("students.txt", "a") as students_file: students_file.write("\n" + str(roll_no) + "\t" + name + "\t" + str(marks)) else: #Create a new file with open("students.txt", "w") as students_file: students_file.write("Roll Number\tName\tMarks") students_file.write("\n" + str(roll_no) + "\t" + name + "\t" + str(marks)) def update_marks(roll_no, new_marks): with open("students.txt", "r") as students_file: lines = students_file.readlines() with open("students.txt", "w") as students_file: for line in lines

Questions about programming?Chat with your personal AI assistant