Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- secretNumber = random.randint(1,100) # Returns a random integer from 1 to 100.
- print('I am thinking of a number')
- print('between 1 and 100.')
- print('Take a guess:')
- userGuess = int(input()) # Whatever the user types is converted to an integer value and stored in userGuess.
- # Keep looping as long as userGuess does not equal secretNumber
- while userGuess != secretNumber:
- if userGuess < secretNumber:
- print('That guess is too low.')
- elif userGuess > secretNumber:
- print('That guess is too high.')
- # Ask the user to guess again.
- print('Take a guess:')
- userGuess = int(input())
- # Go back to the start of this loop, and if the condition is True, repeat the code in the loop.
- # The loop only stops looping when userGuess != secretNumber is False, that is,
- # when userGuess == secretNumber. So if the execution has reached this point, the player has guessed correctly.
- print('That guess is correct!')
- print('Goodbye!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement