Write a Python program that plays a guess-the-number game with magic lists.
The program will play as many games as the user wants. In each game, the program asks the user to think of a number between 1 and 31, inclusive. Then the program presents the user with 5 lists and asks the user if their number is in the list. Based on the users answers of y or n, the program guesses the users number.
- The program works with 5 files, each file contains 16 integers, one number per line.
The filenames are: magicList1.txt, magicList2.txt, magicList3.txt, magicList4.txt, and magicList5.txt
- The program is divided into 3 functions.
1. A createList function that will read in data from one magicList file.The function does the following tasks:
-
- Create an empty list.
- Use the with construct to open the file magicListN.txt, where N is the input argument for the function.
- Loop to read in each line in the file, convert the line to an integer, and store the integer in the list.
- Return the list.
- Note: dont call any list variable with the name list. list is a Python data type and is a reserved word. Some common ways to call a generic list variable are: List or _list or list_ or L , if you dont want to use the more descriptive name magicList.
2. A checkList function that will check whether the user number is in the magic list.The function does the following tasks:
- Use a nested loop to print the magic list (16 numbers) as a table of 4 rows and 4 columns.
- Loop to ask the user if their number is in the list, stop the loop when the user answers y or nThe condition for the loop must be whether the user answers y or n
3. A main function that will:
- Loop to create an outer list of magic lists. The loop will:
- run 5 times to call createList, and each time store the returned magic list into the outer list.
- Loop to let the user keep playing as long as the user wants:
- Create an inner loop that runs 5 times:
- Call checkList to ask the user whether their number is in a particular magic list, passing to checkList one magic list at a time. Recall that the magic lists are elements in the outer list that you created in the step above.
- If the user answer is y and:
- its magicList1, then add 16 to the total
- its magicList2, then add 8 to the total
- its magicList3, then add 4 to the total
- its magicList4, then add 2 to the total
- its magicList5, then add 1 to the total
- Ask the user if they want to continue, and loop back to play again if the answer is y
- Create an inner loop that runs 5 times:
- When done, if the total is non-zero, then print the users numberIf the total is 0, then print an error message
- Dont forget to call the main function so that the program will run.
C. (10 pts) Test your output by running several games, one after another.

![[Solved] Python program that plays a guess-the-number game with magic lists](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[Solved] Payroll calculation program-Python](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.