Dhanu P.

asked • 11/30/22

11.9 LAB: Guess the random number

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.

  1. random.seed(seed_value) seeds the random number generator using the given seed_value.
  2. random.randint(ab) 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.


1 Expert Answer

By:

Anant M. answered • 12/18/22

Tutor
New to Wyzant

Computer science University student with 4+ years experience in python

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.