This is all in Python. Also, the names come from a .txt file that i have...

60.1K

Verified Solution

Question

Programming

This is all in Python. Also, the names come from a .txt filethat i have created with 3 names on it(Jim,Pam,Dwight).

Main Function. Write a program where the userenters a name. Using the read function, check to see if the name isin the text document. If it is, respond back to the user the nameis found within the list.

Read Function. The read function should returnthe contents of the text document as a list.

EXAMPLE OUTPUT
Please enter a name: Jim
Jimis found in the list.
Enter another name (Y/N): Y
Please enter a name: Andy
Sorry, Andy was not found in the list. Would you like to add it?(Y/N): Y
Andrew has been added to the list.
Enter another name (Y/N): N

Write Function. The write function should takethe list and override the file with the new names list in reversealphabetical order with a hard return after each name.

Answer & Explanation Solved by verified expert
3.9 Ratings (417 Votes)
CODEread functiondef readfile opennamestxtrreading all the lines and removing the char n from theend of each linelines xsplitn0 for x in filereadlinesfileclosereturn lineswrite functiondef writelinessotring the list in reverselines    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students