Question: Given the code that reads a list of integers, complete the number_guess() function, which should choose a random number between 1 and 100 by
Given the code that reads a list of integers, complete the number_guess() function, which should choose a random number between 1 and 100 by calling random.randint() and then output if the guessed number is too low, too high, or correct. Import the random module to use the random.seed() and random.randint() functions. random.seed(seed_value) seeds the random number generator using the given seed_value. random.randint(a, b) returns a random number between a and b (inclusive). For testing purposes, use the seed value 900, which will cause the computer to choose the same random number every time the program runs. Ex: If the input is: 32 45 48 80 the output is: 32 is too low. Random number was 80. 45 is too high. Random number was 30. 48 is correct! 80 is too low. Random number was 97. Activate Windows Go to Settings to activate Windows. 1 # TODO: Import the random module 2 3 def number_guess(num): 4 5 6 7 8 9 if __name__ "__main__": 10 # Use the seed 900 to get the same pseudo random numbers every time random.seed (900) 11 12 13 14 15 16 17 18 19 # TODO: Get a random number between 1-100 # TODO: Read numbers and compare to random number == # Convert the string tokens into integers user_input input() user_input.split() main.py tokens = for token in tokens: num = int(token) number_guess(num)
Step by Step Solution
There are 3 Steps involved in it
Heres the completed numberguess function and the main part of the code python TODO Imp... View full answer
Get step-by-step solutions from verified subject matter experts
