Advertisement
Talithacelin

Simple Hangman

Dec 12th, 2022 (edited)
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. import random
  2. import time
  3.  
  4. name = input("What is your name? ")
  5. print ("Hello, " + name, ". It's hangmanin time.")
  6.  
  7. time.sleep(1)
  8. print(20*"-")
  9. print ("Start guessing...")
  10. time.sleep(0.5)
  11.  
  12. words = ["vscode" , "python" , "hangman" , "coding" , "game"]
  13. word = random.choice(words)
  14.  
  15. guesses = ''
  16. life = 5
  17.  
  18. while life > 0:        
  19.     fail = 0            
  20.     for letter in word:      
  21.         if letter in guesses:    
  22.             print (letter,end=""),    
  23.  
  24.         else:
  25.             print ("_",end=""),    
  26.             fail += 1    
  27.  
  28.     if fail == 0:  
  29.         print()      
  30.         print ("YOU WIN!")
  31.         break              
  32.  
  33.     print
  34.     guess = input(" | Guess a character: ")
  35.     guesses += guess                    
  36.     if guess not in word:  
  37.         life -= 1        
  38.         print ("---- Wrong ----")  
  39.         print ("---You have", + life, 'more guesses---' )
  40.         print()
  41.  
  42.         if life == 0:        
  43.             print ("YOU LOSE ..."  )
  44.             print("Better luck next time " + name)
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement