Advertisement
JkSoftware

Day 7 _ Hangman start.2

Nov 10th, 2021
1,142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  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.  
  15. hangword = random.choice(wordlist)
  16. num_ = len(hangword)
  17. blankword = []
  18.  
  19. for letter in hangword:
  20.     blankword.append("_ ")
  21.  
  22.  
  23.  
  24.  
  25. #print(blankword)
  26.  
  27.  
  28. position = -1
  29.  
  30. userguess = input("Guess a letter ").lower()
  31. for letter in hangword:
  32.     position += 1
  33.     print(position)
  34.     if letter == userguess:
  35.         blankword[position] = userguess
  36.         print("Right")
  37.     else:
  38.         print("wrong")
  39. print(blankword)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement