Advertisement
Raulwynn

Untitled

Oct 23rd, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. '''
  2.  
  3. 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.
  4.  
  5. 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.
  6.  
  7. '''
  8.  
  9. #intro
  10. print("Please enter names. Type STOP to stop adding names.")
  11. print("")
  12.  
  13. #function
  14.  
  15. while True:
  16. with open("file.txt", "a") as write:
  17.  
  18. # input
  19. a = input("\tAdd: ")
  20. a = a.capitalize()
  21.  
  22. if a == "Stop":
  23. print("")
  24. print("Names saved successfullly.")
  25. break
  26. elif:
  27. with open("file.txt", "r") as read:
  28. for line in read:
  29. if a in line:
  30. print("#already added.")
  31. else:
  32. write.write(a + "\n")
  33.  
  34. #actions
  35.  
  36. #output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement