Advertisement
CloDz

hangman

Sep 30th, 2020
1,050
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. def insert_word():
  2.     print("Input Sentence:")
  3.     word = input()
  4.     word_list = []
  5.     for letter in word:
  6.         word_list.append(letter)
  7.     return word_list
  8.  
  9.  
  10. def word_underscore_converter(word_list):
  11.     underscored_list = []
  12.     upper_string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
  13.     for letter in word_list:
  14.         if letter in upper_string:
  15.             underscored_list.append("_")
  16.         elif letter in " ":
  17.             underscored_list.append(" ")
  18.     return underscored_list
  19.  
  20.  
  21. def underscore_num_checker(word_list):
  22.     counter = 0
  23.     for letter in word_list:
  24.         if letter == '_':
  25.             counter += 1
  26.     return counter
  27.  
  28.  
  29. def hangman_game(word_list, underscored_word, underscored_num):
  30.     is_word_incomplete = True
  31.     underscored_change = 0
  32.     while is_word_incomplete:
  33.         print("Input letter:")
  34.         letter = input()
  35.         counter = 0
  36.         for i in word_list:
  37.             if i == letter:
  38.                 underscored_word[counter] = letter
  39.                 underscored_change += 1
  40.                 print(underscored_word)
  41.                 counter += 1
  42.             elif i != letter:
  43.                 counter += 1
  44.  
  45.         if underscored_num == underscored_change:
  46.             print("Sentence Completed!")
  47.             is_word_incomplete = False
  48.  
  49.  
  50. print("***THIS GAME IS PLAYED IN ALL UPPER CASE LETTERS***")
  51. word_listed = insert_word()
  52. word_underscored = word_underscore_converter(word_listed)
  53. underscore_count = underscore_num_checker(word_underscored)
  54. print("word_listed is: {}".format(word_listed))
  55. print("word_underscored is: {}".format(word_underscored))
  56. print("This word has {} underscores".format(underscore_count))
  57. hangman_game(word_listed, word_underscored, underscore_count)
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement