Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a program in Python in which the main function creates a list containing 7 randomly generated numbers. The number should be between 0 and

Create a program in Python in which the main function creates a list containing 7 randomly generated numbers. The number should be between 0 and 9 inclusive. Next the user should be prompted to enter 7 numbers between 0 and 9 and these numbers should be stored in another list. Then use a loop to compare the numbers one at a time and count how many are the same. When all 7 are the same, then the user wins $500. When 6 numbers are the same, the user wins $250. When 5 numbers are the same, the user wins $125. When 4 numbers are the same, the user wins $50. When less than 4 numbers are the same, the user does not win anything. To count as a match the numbers must be in the same position in the list. For example if the randomly generated list was [2 7 3 1 9 4 5] and the users list was [3 7 4 2 9 4 5 ], only 4 numbers (7,9,4, and 5) are a match and the user wins $50. Although there are a 3 and 2 in both lists they are not in the same position in both lists and therefore do not count as a match. The main function should output both lists and how much was won. To create the list of random numbers first create an empty list, then use a loop with the append method to add randomly generated values to the list. See Program 3 from Chapter 6 on page 306 and Figure 20 of Chapter 5 on page 245 of your textbook. You should set up your loop to run 7 times. To create the list from the user first create an empty list, then use a loop to prompt the user to enter a number, call a function to check that number (see paragraph below), then append the number to the list. Again, the loop should only run 7 times. Once both lists are created use a third loop to compare the elements of both arrays and count the matches You program should contain a second function that will accept a value and robustly confirm that it is between 0 and 9 inclusive and return a valid value. The user should be prompted to re-enter a value that is not in the proper range. This function should be called immediately after each number is entered by the user and before the value is stored in the list. This function should only accept 1 parameter, the value being checked. The only commands that should be outside of a function is import commands. Remember to write comments for you function to check the validity of input in addition to the overall comments for the program

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

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions

Question

What are the differences between token bucket and leaky bucket?

Answered: 1 week ago