Skip to content

Instantly share code, notes, and snippets.

@timeowilliams
Created September 18, 2020 16:13
Show Gist options
  • Save timeowilliams/4606418a702e40ddf187d098c1790a08 to your computer and use it in GitHub Desktop.
Save timeowilliams/4606418a702e40ddf187d098c1790a08 to your computer and use it in GitHub Desktop.
Practice Python 9: Guess a number
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