I'm new to python and this is code for hangman. randomly taking a word and user is guessing the letters odf the word. This was one of problem from 12 beginner python project of freeCodeCamp.org video.In the video it shows no problem. but when I'm running this i get no error but no output as well.
import random
from words import words
import string
def get_valid_word(words):
word = random.choice(words) # randomly chooses something from the list
while '_' in word or ' ' in word:
word = random.choice(words)
return word.upper()
def main():
word = get_valid_word(words)
word_letters = set(word) # letters in the word
alphabet = set(string.ascii_uppercase)
used_letters = set() # what user has guessed
# getting user input
while len(word_letters) > 0:
# letters used
# ''. join(['a', 'b', ]) --> 'a b '
print('You have used these letters: ', ' '.join(used_letters))
# what current word is( W _ R D)
word_list = [letter if letter in used_letters else '_' for letter in word]
print('current word: ', ' '.join(word_list))
here is the problem. i cannot give any inputs
user_letter = input('Guess a letter: ').upper()
if user_letter in alphabet - used_letters:
used_letters.add(user_letter)
if user_letter in word_letters:
word_letters.remove(user_letter)
elif user_letter in used_letters:
print('You have already used that character.Please try again later')
else:
print('Invalid character.Please try again later')
''' This is my first project and i'm sorry if this is a silly question. Greatly appreciate if someone can help me.If anyone wants to watch the video. Here is the link