please help in PYTHON Write a python script that uses a whil

please help in PYTHON

Write a python script that uses a while statement to create a number guessing game:

1. Use random.randint(a,b) to generate a random number between a=1 and b=1000. You will also need to add an import random command at the start.

2. Ask a player to enter a number (integer) to be guessed. The number is greater than zero but less than or equal to 1000.

3. Use a while statement to give an indication if the number is higher or lower than the guess.

4. The process repeats until the number is guessed or the player types quit.

Hint 1: You need an initial guess (guess=0) to initiate your while statement.

Hint 2: You need two if statements: the first one is to deal with the game quitters

Hint 3: Your conditional while statement should compare the number generated to the current guess with three possible outcomes: high, low or just right.

Hint4: Use the command break to end the game when you win and when you quit.

Solution

import random

randNumber = random.randrange(1, 1000)


userGuess = 0
userGuess1=\'\'
while userGuess < randNumber or userGuess > randNumber:
userGuess1 = input(\"Enter a number (integer) to be guessed (range ..0<num<=1000) or enter \'q\' for exit : \")
if \"q\" == userGuess1:
break
userGuess = int(userGuess1)
if userGuess < randNumber :
print \"Guess is smaller.\"
if userGuess > randNumber:
print \"Guess is larger.\"

  
else :
print(\"Your guess is correct | Number is : \"), randNumber

please help in PYTHON Write a python script that uses a while statement to create a number guessing game: 1. Use random.randint(a,b) to generate a random number

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site