Question
Name Generator Lab Python Reading and Writing Files In this lab, you will use files that contain lists of names, prefixes, and occupations to generate
Name Generator Lab Python Reading and Writing Files In this lab, you will use files that contain lists of names, prefixes, and occupations to generate names for Dungeons and Dragons characters.
Part 1: Reading Files
1) Write a python program that opens a file, reads all of the lines into a list of strings, and closes the file. Use the Readlines() method. Test your programming using the names.txt file provided.
2) Convert the program into a function called loadFile, that receives the file name as a parameter and returns a list of strings.
3) Write a main routine that calls loadFIle three times to load the three data files given into three lists. Then choose a random element from the title list, two from the name list, and one from the descriptor list to generate a name. Print the name be in the form shown (you have to add the "the"): title name the descriptor, For example, King Ludovicus Botolf the Bowman Print the name to the screen. Submit your python file (.py) to Sakai
Part 2: Writing Files
(Optional Extra Credit 20 pts) Modify the program to generate 10 names and store them in a list. Write a function, dumpFile that writes the list to a file called "CharacterNames.txt" There should be one Character Name on each line in the file. Test the program to be sure it works
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started