Home > Net >  Infinite loop not checking for string size and belonging to alphabet
Infinite loop not checking for string size and belonging to alphabet

Time:08-10

I've been trying to make a check for if the input (guesses) belongs to the alphabet and if it's a single character for my simple hangman game, but when I try to run the program it just ignores the entire if sentence. It's been working everywhere else and I just can't find the source of the problem. Here is my code:

def eng():
    letter_list = []
    global word
    global letter
    g = 0
    lives = 10
    while True:
        word = input("Insert The Word: ")
        if not word.isalpha():
            print("Only letters of the English alphabet are allowed")
        else:
            print(letter)
            break
    cls = lambda: print('\n' * 256)
    cls()
    ready_letters = list(set(word.lower()))
    while True:
        q = len(ready_letters)
        print(q)
        while True:
            letter = input("Your guess: ")
            if not letter.isalpha() and len(letter) != 1:
                print("You can make a guess with only one letter of the English alphabet")
            else:
                break
        print(letter_list)
        if letter in ready_letters and letter not in letter_list:
            letter_list  = letter
            print("Nice")
            g  = 1
            if g == q:
                print(f"The word was: {word}")
                print("GG,            
  • Related