Skip to content

Instantly share code, notes, and snippets.

@davegotz
Created January 24, 2019 15:47
Show Gist options
  • Save davegotz/b3ba7bc51c7fe8bf45b61b273ff5f22c to your computer and use it in GitHub Desktop.
Save davegotz/b3ba7bc51c7fe8bf45b61b273ff5f22c to your computer and use it in GitHub Desktop.
Final version of higher/lower
#####
# Start with player 1, who chooses the number to guess
#####
# Ask player 1 for a value between 0 and 100
target_number = int(input('Player 1: Enter a number between 0 and 100: '))
#####
# Now it is time for player 2 to guess...
#####
# Clear the screen so player 2 can't cheat!
for linenum in range(20):
print()
print("Player 2... YOUR TURN!")
# Get player 2's first guess.
guess_number = int(input('Make your first guess: '))
count = 1
# While the guess is wrong
while guess_number != target_number:
# Tell player 2 if the guess is too high or too low.
if guess_number > target_number:
print("Too high!")
else:
print("Too low!")
# Have player 2 guess again.
guess_number = int(input('Make your next guess: '))
count += 1
# Congratulate player 2 for getting it right!
print("Congrats! You guessed it in", count, "guesses.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment