Advertisement
JkSoftware

Day 7 _ Hangman start.3

Nov 10th, 2021
1,255
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2.  
  3.  
  4. wordlist = ["ardvark", "baboon", "camel"]
  5.  
  6. #todo #1 randomly choose word from list and assign it a variable
  7. #todo #2 ask user to guess a letter and assign it a variable
  8. #todo #3 check if letter is in the chosen word
  9. ########################
  10. #todo #4 create a empty list with the same amount of blanks as letters
  11. #todo #5 loop through each posiion of hangword and if the letter
  12. #matches chnage the blank with that letter
  13. #todo #6 print the blanks with the guessed letter
  14. #todo #7 use while loop to guess again
  15. endgame = False
  16. hangword = random.choice(wordlist)
  17. blankword = []
  18.  
  19. for letter in hangword:
  20.     blankword.append("_ ")
  21.  
  22.  
  23.  
  24. while not endgame:
  25.     print(blankword)
  26.     userguess = input("Guess a letter ").lower()
  27.     for position in range(len(hangword)):
  28.         letter = hangword[position]
  29.         if letter == userguess:
  30.             print("Right!")
  31.             blankword[position] = letter
  32.         else:
  33.             print("Wrong!")
  34.     if "_ " not in blankword:
  35.         endgame = True
  36.         print("You Win!")
  37.  
  38.  
  39. #print("Congrats")
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement