I want to input a name that is already in a file and when it is inputed it deletes the name from the file
6/29/2022 7:08:43 PM
Uwalaka Ugochukwu9 Answers
New AnswerYou may want to brush up on your syntax. name = input() with open(<file>) as names: name_list = names.readlines() if name in name_list: index = 0 for n in range(len(name_list)): if name_list[index] == name: name_list.pop(index) with open(<file>, w) as file: file.writelines(name_list)
Create a file with a list of patients awaiting organ donation, write a program where i can enter a patient's name and if the patient exists delete the patient's name from the file but if the patient doesn't exist add it to the file.
Name=input() X=open(‘txt’, ‘w+’) X.write(the names goes here) Line=x.read() For lines in line: If line == name: Line.remove() Else: X.write(name)
Create a file with a list of patients awaiting organ donation, write a program where i can enter a patient's name and if the patient exists delete the patient's name from the file but if the patient doesn't exist add it to the file.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message