Question: Application In this assignment you will write functions, use functions and their appropriate parameters, and use random numbers generated by the computer. Background Many states




Application In this assignment you will write functions, use functions and their appropriate parameters, and use random numbers generated by the computer. Background Many states offer a state lottery. These lotteries come in many forms but a common form is to pick a series of numbers; this can be 5, 6, or 7 numbers. Then a random series of numbers are selected by the organization hosting the lottery. If the numbers picked by a person, match some (or better, all) of the numbers that the organization picked, there is a larger reward in the form of money. The odds of you winning the lottery are very, very, low. In fact, it is more likely that a rock from outer space comes in line with our planet, enters the atmosphere at an angle which does not miss the planet completely, fails to burn up from the resistance with our 300 miles of atmosphere, eventually gets to the surface, strikes you, of all people on the earth, with enough force so that you die. Couple this with the fact that humans are naturally bad at picking lottery numbers and it is surprising that people even play the lottery. This is often why it is said that the lottery is "a tax on people who are bad at math." Despite all of this, people continually play the lottery. Now, if a person decides that they are an exception to math and decide to play the lottery anyway, it is better to have a computer randomly pick the numbers for you than to pick them yourself. This is because when people pick, what they assume are random, numbers, they tend to pick numbers based on a pattern, not truly random ones. In fact, a survey from the 2014 book The Grapes of Math by Alex Bellos, found that when asking people to pick a random number between 1 and 100, almost 10% picked 7 and almost 8% picked 3; followed by 8.4,5, and 13 as the most common numbers picked. Instructions You will be creating a program that will use random numbers to create a set of possible lottery numbers. To use the application, the user will enter a quantity of individual numbers will be part of each overall lottery number. Each of these individual numbers will be between 6 and 90 (inclusive). The user will then need to enter how many lottery numbers will be generated. Then using pseudo random number generation, available using the random module, the program will display to the user a list of lottery numbers. Even though normal lottery numbers would not have duplicate numbers, for simplicity, we will allow for repeated numbers in our lottery numbers. This means that :06:52::85:06:85:-33: would be an acceptable number, despite the 6 (as well as 85) appearing twice Create a Python script 1. Name the script lotto_numbers.py 2. Write code to create the following functionality a. Import the random library b. Create a function named get_number_in_each which accepts nothing (has no parameters) and prompts the user for the number of individual numbers to generate in each lottery number. This function needs to return an integer representation of the user's response. 1. If they enter 5. each lottery number will have 5 numbers:72:30:25:46:61: ii. If they enter 3, each lottery number will have only 3 numbers:72:30:25: c. Create a function named get how_many_to_list which accepts nothing (has no parameters) and prompts the user for the number of lottery numbers to display. This function needs to return an integer representation of the user's response. d. Create a function named format number which accepts an integer and returns a string representation of the number in the correct format. 1. You must use the format function. (parameter) returns 1. This is the function introduced the first week of value given class. 4 :04: ll. The format must be (number): 57 :57: 38 :38: 1. Examples in the table to the right 10 :10: e. Create a function named get_number which accepts two integers, one is the minimum and the second is the maximum value that could be returned. The function will return a random integer which falls within the minimum and maximum values specified (inclusive). 1. You must use the randrange function. 1. Do not use the randint function. 4 5 f. Create a function named next_lotto_number which accepts an integer for how many individual numbers are in the lotto number and returns (parameter) Minimum value a string representation of a single lotto number. value given 1. You will need get a new random number for each 3 :59.:89:23: individual number in the lotto number. :14:22:19-63: 1. Each number must fall between 6 and 90 :72:30::25:46::61: 6 (inclusive) -66::73:40:74:66:41: a. You need to use the function :54::85: which you wrote to get your next number. ii. Each number will need to be formatted using the function you wrote. ill. Combine each formatted number together to make the final lottery number. 1. Examples in the table provided above 2 & You will need to call each function appropriately and as needed to finish the code. h. For each lotto number you need to list to the user, 1. Get the lotto number and display it to the user in the format of: 1. Number (order) (lotto_number} 2. For example: Number 1 :25:79.-23:-90.-30:23:75: Number 2 :45:49:13:43:76:34:58: Number 3 :62:67:11:42:16:55:76: 1. Let the user know how many numbers were displayed. Example outputs: You do not have to match my format, but the output should be nicely formatted. Each lotto number has how many numbers? 3 How many lotto numbers should I generate? 6 Number 1 Number 2 Number 3 Number 4 Number 5 Number 6 :32::67::50: :52: :21: :75: :28::78::35: :74: :74::84: : 17::88::49: :36::74: :14: 6 random lottery numbers were generated Each lotto number has how many numbers? 6 How many lotto numbers should I generate? 2 Number 1 Number 2 :28::85::45::52::78::11: :10::88::69: :77::18::84: 2 random lottery numbers were generated Each lotto number has how many numbers? 3 How many lotto numbers should I generate? 3 Number 1 Number 2 Number 3 :50::10::30: :78::34: :51: :70::32::72: This application generates possible lotto numbers; assuming that the numbers will be from 6 to 90 (inclusive). Please first enter the quantity of numbers in each lotto number. And then enter how many lotto numbers you would like to generate. A list of possible lotto numbers will then be shown. Each lotto number has how many numbers? 5 How many lotto numbers should I generate? 4 Number 1 Number 2 Number 3 Number 4 :31::70::40::37::69: :68::50::34: :24: :10: :63::08::90:: 17::73: :89::60::88::69::47: 4 random lottery numbers were generated Tips: You may find it useful, for testing purposes, to temporarily assign a seed at the start of your program If you do this, the values will not change and you can check for patterns. Use the following code to do this: random.seed (3) If you use the seed of 3, with a minimum of 1 and the maximum of 10, you should get the following random numbers from your get_number function: 4,10,9,3,6,10,8, 10, 2, 10, etc. If you use the seed of 3, with a minimum of 1 and the maximum of 90, you should get the following random numbers from your get_number function: 31, 76, 70, 17, 48, 78, 61, 81, 75, 9, etc. If you use the seed of 3, with a minimum of 6 and the maximum of 90, you should get the following random numbers from your get_number function: 36,81,75,22,53,83,66,86, 80, 14, etc. Using the format( function to specify how many digits an integer will fill uses padding. Consult the slides from week 1 for formatting with padding
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
