Skip to content

Instantly share code, notes, and snippets.

@pdbartsch
Created February 7, 2019 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdbartsch/239ecd796a3bbf4762c7a409e4285f15 to your computer and use it in GitHub Desktop.
Save pdbartsch/239ecd796a3bbf4762c7a409e4285f15 to your computer and use it in GitHub Desktop.
import random
num = random.randrange(0,100,1)
score = 0
while True:
guess = input("Guess the number between 1 and 100? -- Type exit to end. ")
if guess.lower() == 'exit':
break
else:
gnum = int(guess)
if gnum > num:
print('lower')
score += 1
elif gnum < num:
print('higher')
score += 1
else:
score += 1
print('Yay! The number was', num, '!')
if score <= 5:
print('You guessed it in only', score, 'tries!')
elif score <= 10:
print('You guessed it in', score, 'tries.')
else:
print('Better luck next time. It took you', score, 'tries.')
num = random.randrange(0,100,1)
score = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment