Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Create a program that asks the user for names, which are written to a file (append?). The program should continue asking for names until the user selects no. Display all names in the file.
- Next, ask the user for a name; read from the file to determine if that name is already in the file, and display an appropriate message.
- '''
- #intro
- print("Please enter names. Type STOP to stop adding names.")
- print("")
- #function
- while True:
- with open("file.txt", "a") as write:
- # input
- a = input("\tAdd: ")
- a = a.capitalize()
- if a == "Stop":
- print("")
- print("Names saved successfullly.")
- break
- elif:
- with open("file.txt", "r") as read:
- for line in read:
- if a in line:
- print("#already added.")
- else:
- write.write(a + "\n")
- #actions
- #output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement