Skip to content

Instantly share code, notes, and snippets.

@jjlumagbas
Last active November 17, 2016 01:42
Show Gist options
  • Save jjlumagbas/381a3aa1fc40513556f51449daad4417 to your computer and use it in GitHub Desktop.
Save jjlumagbas/381a3aa1fc40513556f51449daad4417 to your computer and use it in GitHub Desktop.

Guessing games

How to hide user input

import getpass
age = getpass.getpass('Enter your age:')
print("Entered age is: " + age)

Guess my age

Player 1 enters his age, and Player 2 tries to guess it. Reponse from the computer is either "Lower" or "Higher" depending on Player 2's guess, until Player 2 gets it right.

Player 1 enter your age:
Player 2 enter your guess: 20
Nope! Lower: 16
Nope! Higher: 18
Nope! Lower: 17
17 is correct!

Hangman

Player 1 enters a secret word and Player 2 tries to guess it. After every wrong guess, the computer highlights which letters Player 2 got right.

Player 1 enter your secret word:
Player 2 enter your guess: banana
Nope! You got these letters right: _a_a_a
Guess again: pineapple
Nope! You got these letters right: p__eapple
Guess again: apple
apple is correct!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment