Created
September 18, 2020 16:13
-
-
Save timeowilliams/4606418a702e40ddf187d098c1790a08 to your computer and use it in GitHub Desktop.
Practice Python 9: Guess a number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random #Importing the random module | |
actual = random.randint(1, 9) | |
i = 0 #Setting up the counter/Initialization | |
guess = input('Try to guess what number I''m thinking about(from 1 - 9): ') | |
while guess != "exit": # We want this to run until the user enters the word exit. | |
if int(guess) == actual: | |
print('You entered the right answer') | |
elif int(guess) > actual: | |
print('You entered too high!') | |
elif int(guess) < actual: | |
print('You''ve entered too low') | |
guess = input('Want to play again? Enter a number or enter exit to quit: ') | |
i += 1 | |
print('You''ve played the game '+ str(i) + ' times.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment