PW Akshay

Generation

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

def create(name, roll_no): file = open("student.txt", 'w') file.write("Name: " + name + "\n") file.write("Roll number: " + roll_no) file.close() def search(roll_no): file = open("student.txt", 'r') for line in file: if line.startswith("Roll number:"): if line[13:] == roll_no: print("Found") return print("Not Found") create("Rohan", "17BCE0522") search("17BCE0522")

Questions about programming?Chat with your personal AI assistant