Output:

Guess a number: 28

Sorry the number was: 29

And it will keep doing that until, you guessed the right number. Therefore my question is how to update the random number, every time when the person guesses the right number?

import random random_number, lucky_number = random.randint(0,100), 0 lucky_number = int(input("Guess a number:")) if lucky_number != random_number: while random_number != lucky_number: lucky_number = int(input("Guess a number:")) print("The number was %d." %(random_number)) elif random_number == lucky_number: print("You have guessed the right number!") break