Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 18th International Conference Dasfaa 2013 Wuhan China April 22 25 2013 Proceedings Part 2 Lncs 7826

Authors: Weiyi Meng ,Ling Feng ,Stephane Bressan ,Werner Winiwarter ,Wei Song

2013th Edition

3642374492, 978-3642374494

More Books

Students also viewed these Databases questions

Question

Identify the potential uses of molecular genetics research.

Answered: 1 week ago