Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import time
- name = input("What is your name? ")
- print ("Hello, " + name, ". It's hangmanin time.")
- time.sleep(1)
- print(20*"-")
- print ("Start guessing...")
- time.sleep(0.5)
- words = ["vscode" , "python" , "hangman" , "coding" , "game"]
- word = random.choice(words)
- guesses = ''
- life = 5
- while life > 0:
- fail = 0
- for letter in word:
- if letter in guesses:
- print (letter,end=""),
- else:
- print ("_",end=""),
- fail += 1
- if fail == 0:
- print()
- print ("YOU WIN!")
- break
- print
- guess = input(" | Guess a character: ")
- guesses += guess
- if guess not in word:
- life -= 1
- print ("---- Wrong ----")
- print ("---You have", + life, 'more guesses---' )
- print()
- if life == 0:
- print ("YOU LOSE ..." )
- print("Better luck next time " + name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement