0

I am working on a project that picks a random number and provides two games in result to it. I am in the process of asking what mode the user wants to play so I put an if and elif statement. The first if statement is great and works perfectly, but if the if statement is false it will not run the parameters by the elif statement, it will just print the test text for the if statement as if it was true.

code:

import random
jef = random. randint(0,10)
start = input("Hello user, this is the number game, 
I pick a random number from 1-10 you guess, ok?.")
if start.upper() == "OK":
    choice = input("Ok would you like to play the 
gamble mode or the guess game?")
    if choice.upper() == "GAMBLE" or "GAMBLE MODE":
        print("gamble")
    elif choice.upper() == "GUESS" or "GUESS GAME":
            print("guess")
BroWhat
  • 13
  • 2

2 Answers2

3

Your if statement is essentially evaulating to:

if choice.upper() == "GAMBLE" or True:

as the second condition is simply a string, and non-empty strings are True.

You can fix this like this

if choice.upper() == "GAMBLE" or choice.upper() == "GAMBLE MODE":

OR

if choice.upper() in ["GAMBLE", "GAMBLE MODE"]
HPringles
  • 1,042
  • 6
  • 15
2
    if choice.upper() == "GAMBLE" or "GAMBLE MODE":

is parsed as

    if (choice.upper() == "GAMBLE") or "GAMBLE MODE":

which is basically:

    if (choice.upper() == "GAMBLE") or True:

which is basically:

    if True:

You can fix this by doing:

    if choice.upper() == "GAMBLE" or choice.upper() == "GAMBLE MODE":

or by doing:

    if choice.upper() in ("GAMBLE", "GAMBLE MODE"):
Bill Lynch
  • 80,138
  • 16
  • 128
  • 173