Skip to content

Instantly share code, notes, and snippets.

@richardbwest
Last active July 22, 2016 14:40
Show Gist options
  • Save richardbwest/2f9f917fc009693c18a4cdb2e28c53e4 to your computer and use it in GitHub Desktop.
Save richardbwest/2f9f917fc009693c18a4cdb2e28c53e4 to your computer and use it in GitHub Desktop.
def checkWinLose():
global lives #These variables need to global so that they save outside of the function
global chosenWord
global usedLetters
if lives == 0: #If you have no lives the you have lost!
os.system('clear')
print("\n\nYou lose!!!!!")
input("\n\nPress enter to start again")
chosenWord = random.choice(wordsList)#After here reset lives,empty usedLetters and pick a new word.
lives = 6
usedLetters = []
else:
won = True #Assume that the user has won....
for letter in chosenWord:
if letter in usedLetters:
continue
else:
won = False # Unless you can't find the letter from the hidden word in the userLetters list!
if won:
print("\n\nYou win!!!!")
input("\n\nPress enter to start again.")
chosenWord = random.choice(wordsList)#This code features some duplication so should really be in a separate function.
lives = 6
usedLetters = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment