Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- #---------------------------lists and variables-------------------
- words=["apple","programming","christmas","Hangman"]
- word=random.choice(words)
- tries=0
- guessed_letters=''
- #---------------------------Functions-----------------------------
- def check(guess):
- if guess.lower()==word.lower():
- print("Correct! It only took you %s tries." % tries)
- elif len(guess)==0 or len(guess)>=2:
- print("Invalid.This is not counted as a try.")
- main()
- elif len(guess)== len(word):
- print("Nice try, but that was not the word:")
- tries+=1
- main()
- elif guess.isalpha():
- global guessed_letters
- if guessed_letters.find(guess)>-1:
- print("You have already guessed that letter.")
- main()
- else:
- guessed_letters= guessed_letters+guess
- pass
- else:
- print("Invalid.This is not counted as a try.")
- main()
- def board():
- for letter in word:
- if guessed_letters.find(letter)>-1:
- print(letter, end=" ")
- else:
- print("-",end=" ")
- print()
- def main():
- global tries
- while True:
- if tries>=10:
- print("You got hung! The word was %s." % word)
- break
- board()
- print("Tries you took out of 10:%s" % tries)
- print("The word contains %s letters." % len(word))
- guess=input("Guess a letter or the word itself:")
- check(guess)
- tries+=1
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement