Created
October 24, 2013 21:27
-
-
Save imjohsep/7145333 to your computer and use it in GitHub Desktop.
Written by the Introduction to Python class at Noisebridge during October 23rd's class.
I've refactored the our original code, so we now have one function in main running the two game functions and additional comments for each definition.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/pyhton | |
''' | |
password_guess.py takes a user provided password and gives the next user | |
3 attempts to correctly guess the password before exiting the script. | |
''' | |
def checkpassword(guess, password): | |
''' | |
Verifies whether a guess is correct match to a user's password | |
''' | |
if guess == password: | |
print "good job!" | |
exit(1) | |
else: | |
print "password not match" | |
def vault(password): | |
''' | |
Vault records guesss attempts and passes guesses and password | |
to checkpassword(). | |
''' | |
attempt = 1 | |
while attempt < 4: | |
guess = raw_input("Make your guess: ") | |
checkpassword(guess, password) | |
attempt += 1 | |
print "sorry too many trys..." | |
if __name__ == '__main__': | |
print "User, enter your password por favor: " | |
password = raw_input() | |
vault(password) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment