Answer:
Following are the code to this question:
import random #import package
def number_guess(num): #define method number_guess
n = random.randint(1, 100) #define variable n that hold random number
if num < n: #define if block to check gess number is less then Random number
print(num, "is too low. Random number was " + str(n) + ".") #print message
elif num > n: #check number greater then Random number
print(num, "is too high. Random number was " + str(n) + ".") #print message
else: #else block
print(num, "is correct!") #print message
if __name__ == '__main__': #define main method
random.seed(900) #use speed method
user_input = input() #define variable for user_input
tokens = user_input.split() #define variable that holds split value
for token in tokens: #define loop to convert value into string token
num = int(token) # convert token value in to integer and store in num
number_guess(num) # call number_guess method
Output:
33
33 is too low. Random number was 80.
Step-by-step explanation:
In the above-given python code, first, we import the random package, in the next line, a method number_guess is defined, that accepts num parameter, in this method, we store the random number in n variable and check the value from the conditional statement.
- In this, we check value is less than from random number, it will print message too low, and its Random number. otherwise, it will go in the elif section.
- In this section it will check the value is greater than from a random number, it will print the message to high, and its Random number. otherwise, it will go to else section.
- In this, it will prints number and it is correct.
- In the main method, we input value, and use a token variable to convert the value into string token, and then convert its value into an integer, and then call the method number_guess.