Lesson 10: Hangman & Data mining...

posted Dec 21, 2017, 7:36 AM by Attila Lengyel   [ updated Dec 21, 2017, 7:58 AM ]
import word_dict
import random

analytics = []


count = []
count.append(0)
count.append(0)

for x in range(0, len(word_dict.db)):
  for y in word_dict.db[x]:
    if (y == 'a'):
      count[0] += 1
    if (y == 'e'):
      count[1] += 1
print(count)

print("Let's play Hangman")

select = random.randint(0,len(word_dict.db))
word = word_dict.db[select]

word_dash = ""
for x in range(0, len(word)):
  word_dash += "_ "
 
print (word_dash)

cont = True
good_letters = ""
 
while cont:

  guess = input("Guess a letter:")
 
  if word.find(guess) > -1:
    print("Correct guess!")
    good_letters += guess
  else:
    print("Wrong guess!")
 
  cont = False 
  word_dash = ""
  for x in range(0, len(word)):
    if good_letters.find(word[x]) > -1:
      word_dash += word[x] + " "
    else:
      word_dash += "_ "
      cont = True
 
  print(word_dash)



Comments