Must be python format

Create a program which will choose a random number between 1 and 1000.
Ask the user to guess at the number, and give the user feedback if their guess is too high or too low.
Also, keep track of the number of guesses that the user makes.
"Redirect" the user if they enter a number outside of the range of 1 to 1000, and the error should not count as one of their guesses.
When the user finally guesses the answer, congratulate them and inform them how many guesses it took them to arrive at the correct number. (and the program should end)
Much of this will be done using the WHILE command, and perhaps an IF statement.

(sample output of the program is below)

Guess a number between 1 and 1000? 500
Your guess is too low! Try a higher number.

Guess a number between 1 and 1000? 2000

Whoops, guess a number between 1 and 1000? 750
Your guess is too high! Try a lower number.

Guess a number between 1 and 1000? 625
Your guess is too high! Try a lower number.

Guess a number between 1 and 1000? 560
Your guess is too high! Try a lower number.

Guess a number between 1 and 1000? 530
Your guess is too high! Try a lower number.

Guess a number between 1 and 1000? 515
Your guess is too low! Try a higher number.

Guess a number between 1 and 1000? 520

Your guess is too high! Try a lower number.

Guess a number between 1 and 1000? 517

Your guess is too low! Try a higher number.

Guess a number between 1 and 1000? 518

You got it! The number is 518 and you got it in 9 guesses!

Respuesta :

import random

to_guess = random.randint(1, 1000)

count = 0

guess = 0

while guess != to_guess:

   guess = int(input("Guess a number between 1 and 1000? "))

   while guess < 1 or guess > 1000:

       guess = int(input("Whoops, guess a number between 1 and 1000? "))

   count += 1

   if guess > to_guess:

       print("Your guess is too high! Try a lower number.")

   elif guess < to_guess:

       print("Your guess is too low!. Try a higher number.")

print("You got it! The number is " + str(to_guess)+" and you got it in " + str(count) + " guesses!")

I hope this helps!

ACCESS MORE
EDU ACCESS