Skip to content

Instantly share code, notes, and snippets.

@shamikalashawn
Last active February 7, 2017 20:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shamikalashawn/a452e0eed20677f55b71093d9c50bbfe to your computer and use it in GitHub Desktop.
Save shamikalashawn/a452e0eed20677f55b71093d9c50bbfe to your computer and use it in GitHub Desktop.
Guess a number between 0 and 100. You'll get clues as to whether your guess is "higher" or "lower" than the actual answer.
from random import randint
print ('---------------------------------------------' + '\n' + ' GUESS THE NUMBER APP' + '\n' + '---------------------------------------------' + '\n')
number = randint(1, 100)
while True:
guess = input('Guess a number between 0 and 100 ("quit" to stop): ')
if not guess.isdigit():
print("That's not a good guess! Please type a number.")
elif int(guess) < number:
print('Sorry but {} is LOWER than the number'.format(guess))
elif int(guess) > number:
print('Sorry but {} is HIGHER than the number'.format(guess))
elif int(guess) == number:
print("YES! You've got it. The number was {}.".format(number))
play_again = input('Would you like to play again? Yes or No?: ')
if play_again.lower() == 'yes':
number = randint(1, 100)
elif play_again.lower() == 'no':
print('Well, hope you had fun! Thanks for playing. ^_^')
break
elif guess.lower() == 'quit':
print('Well, hope you had fun! Thanks for playing. ^_^')
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment