0

I was writing this simple code in Python to make a guessing game and it works with a word. But i want it to recognize the word if any part of it is capitalized. I'm a begginer in Python so ignore my mistakes. Posting some code here;

word = "no"
word2 = "No"
word3 = "NO"
guess = ""
guess_count = 0
guess_limit = 3
out_of_guesses = False

print("-----GUESS THE WORD!-----")
print("Which word comes here? ---> __ .")
while guess != word and not(out_of_guesses):
    if guess_count < guess_limit:
        guess = input("Enter Your Guess: ")
        guess_count += 1
    else:
        out_of_guesses = True
if out_of_guesses:
    print("You are out of guesses, You Lose! ")
else:
    print("You are Right!")
print('The Word was "no".')

This code works but i want it to consider the variables: word 2 and word 3. This is the code that doesn't work.

word = "no"
word2 = "No"
word3 = "NO"
guess = ""
guess_count = 0
guess_limit = 3
out_of_guesses = False

print("-----GUESS THE WORD!-----")
print("Which word comes here? ---> __ .")
while guess != word or guess != word2 or guess != word3 and not(out_of_guesses):
    if guess_count < guess_limit:
        guess = input("Enter Your Guess: ")
        guess_count += 1
    else:
        out_of_guesses = True
if out_of_guesses:
    print("You are out of guesses, You Lose! ")
else:
        print("You are Right!")
print('The Word was "no".')

I would love to hear about a solution or a better way to do the same.

Sneakoz
  • 43
  • 3
  • 1
    In this case, if you don't care about capitalization, you could just use word.lower(). Just like arithmetic, you can group things with parenthesis (), so you can group (guess != word or guess != word2 or guess != word3) for an overall truth. – Andrew Holmgren Jul 15 '22 at 11:00
  • See the duplicate for details. `and` has higher precedence as `or`, so it should be `while (guess != ... or ... or ...) and not out_of_guesses`. Note that there is no need for parentheses after `not`, as `not` is not a function. – Thierry Lathuille Jul 15 '22 at 11:01

0 Answers0