+ 2
How to get random numbers as input in python ?
I made a simple number guessing game in python.Which has value of the number stored in variable. I want to generate random numbers for the number which has to be guessed by user. https://code.sololearn.com/c77550hdXQRH/?ref=app
4 Answers
+ 4
Use the randint method in random module.
randint(lower bound, upper bound + 1) generates a random number.
https://code.sololearn.com/clbZ94AMExoV/?ref=app
+ 1
Take a loop and accept input in loop, if you guessed right then break loop , otherwise keep on giving input..
edit:
while True :
guessNumber = int(input("Please guess the number:\n ")
if guessNumber == number:
print("You won!, you guessed it right!")
break
elif guessNumber < number:
print("It is too low, try again!")
elif guessNumber > number:
print("It is too high, try again!")
0
But how do i guess the number
0
Each time i have to run the code again and that means each time a different number will be generated