acclivity

pyHangmanGame

Feb 12th, 2022 (edited)
1,160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. import random
  2.  
  3.  
  4. def showman(count):
  5.     manparts = [" ", "  o", " /|\\", " / \\", " "]
  6.     structures = ["|____", "|", "|", "|", "|____"]
  7.     for n, line in enumerate(structures):
  8.         for ch in manparts[n]:
  9.             if not count:
  10.                 break
  11.             if ch != " ":
  12.                 count -= 1
  13.             line += ch
  14.         print(line)
  15.     print("Your word: ", "".join(blanks), "             Other letters tried: ", tried)
  16.  
  17.  
  18. words = ["these", "are", "the", "most", "wow", "basic", "english", "words", "check",
  19.          "learn", "they", "happy", "fish", "common", "bag", "account", "for", "store",
  20.          "speak", "read", "writing", "going", "ball", "smile", "run", "day", "night",
  21.          "blunt", "with", "string", "until", "crowd", "empty", "tough", "fancy"]
  22.  
  23. while True:
  24.     answer = random.choice(words)
  25.     anslist = list(answer)
  26.     blanks = ["-"] * len(answer)
  27.     tried = ""
  28.     lives, livesleft = 6, 6
  29.     while livesleft:
  30.         showman(lives - livesleft)
  31.         char = input("Enter a letter guess: ")
  32.         if char not in anslist:
  33.             livesleft -= 1
  34.             tried += char
  35.         else:
  36.             while char in anslist:
  37.                 idx = anslist.index(char)
  38.                 blanks[idx] = char
  39.                 anslist[idx] = "."
  40.         if "-" not in blanks:
  41.             break
  42.     showman(lives - livesleft)
  43.     if "-" not in blanks:
  44.         print("You win!")
  45.     else:
  46.         print("Sorry, you failed. The word was", answer)
  47.  
  48.     ch = input("\nPlay again? (Y/N): ")
  49.     if not ch.lower().startswith("y"):
  50.         break
  51. print("Goodbye")
  52.  
Add Comment
Please, Sign In to add comment