PW Akshay


generate functionFri, 02 Dec 2022

Create a binary file with name and roll number. Search for a given roll number and display the name, if not found display appropriate message

import os def createFile(filename, rollno, name): try: file = open(filename, "wb") file.write(str(rollno) + "," + name + "\n") file.close() print("File created successfully") except IOError as e: print("Error in file creation: " + str(e)) def searchFile(filename, rollno): try: file = open(filename, "rb") for line in file: roll, name = line.decode().split(",") if roll == str(rollno): print("Name: " + name) break else: print("Not Found") file.close() except IOError as e: print("Error in file read: " + str(e)) def main(): filename = input("Enter filename: ") ch = 0 while ch != 3: print("1. Create File") print("2. Search File") print("3

Questions about programming?Chat with your personal AI assistant