lundi 31 mai 2021

Why is my Python code ignoring my if-statement and quitting? [closed]

I am trying to write a python word puzzle game which may have multiple players and points are given based on the length of the words found.

Here is my function which 'plays' the game, however, it always results in "Game over!" no matter if my answer is right or wrong. So it quits the game every time.

def play_game(players, board , words, answers):
found_words = []
num_remaining = num_words_on_puzzle - len(found_words)
player_num = 0
while num_remaining > 0:
    print_headers(players, board, found_words, num_remaining)

    guess_input = input("{player}, make a guess: ".format(
        player=players[player_num % len(players)][0]))
    
    # Allow player to quit
    if guess_input.lower() == 'q' or 'quit':
        break 

    # Determine if the guess is valid
    guess = convert_guess(guess_input)
    
    if is_valid_answer(answers, guess):
        # Update a players score since answer is valid
        update_score(players[player_num % len(players)], matching_answer(answers, guess))
        # Add this word to found_words list
        found_words.append(matching_answer(answers, guess))
        
        print("Congratulations, you found '%s'." % matching_answer(answers, guess))
        print("That's %d points(s)." % word_score(matching_answer(answers, guess)))

    else:
        print("Sorry, that is incorrect.")

    num_remaining = num_words_on_puzzle - len(found_words)
    player_num += 1

print("\nGame over!\n")
print("The final scores are: \n")
print_score(players)
print(answers)

I hope someone can help me see where my issue is.

Aucun commentaire:

Enregistrer un commentaire