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:

Respuesta :

Answer:

see explaination

Explanation:

import random

def number_guess(num):

n = random.randint(1, 100)

if num < n:

print(num, "is too low. Random number was " + str(n) + ".")

elif num > n:

print(num, "is too high. Random number was " + str(n) + ".")

else:

print(num, "is correct!")

if __name__ == '__main__':

# Use the seed 900 to get the same pseudo random numbers every time

random.seed(900)

# Convert the string tokens into integers

user_input = input()

tokens = user_input.split()

for token in tokens:

num = int(token)

number_guess(num)

fichoh

The program which displays if user supplied inputs is equivalent to a random seeded number is given below. The program ls written in python 3 ;

import random

#import the random module

def number_guess(num):

#initialize a function named number_guess which takes in a single parameter

get_num = random.randint(1, 100)

#get a random integer between 1 and 100 ;assign to a variable named get_num

if get_num == num :

print(num, ' is correct')

elif get_num > num :

print(num, ' is too low. Random number is ', get_num)

elif get_num < num :

print(num , ' is too high. Random number is ', get_num)

#use if and elif statements to compare the num and get_num values and display appropriate statements.

if __name__ == "__main__" :

random.seed(900)

#seed the random number for reproducibility

user_input = input()

#prompts user for input seperates by while spaces

tokens = user_input.split()

#splits the inputs based on white space

for token in tokens :

#iterate through the list of tokens

num = int(token)

#assign each iterated value to the num variable

number_guess(num)

#pass as an argument into the function

A sample run of the program is attached including the script.

Learn more :https://brainly.com/question/14521251

Ver imagen fichoh
Ver imagen fichoh