-3

I was just trying to make a text-adventure game but when I tried to make an if-else statement that checks the user input incase-sensitive, it doesn't work when I tried to use the lower function (or anything else).

Here is an actual code:

def intro():
    global StayEnding
    print("You wake up in your room like usual.")
    time.sleep(1)
    print("But this time, something was different.")
    time.sleep(1)
    print("You can feel power rushing down to your body, magic flowing through your veins.")
    time.sleep(1)
    print("Are you powerful? Can you cast magic? You shouldn't know now. It's time to go.")
    userinput = input("Do you want to stay or go? ")
    if userinput.lower() == "Stay":
        print("You never went outside, you decided to stay in your house.")
        time.sleep(1)
        print("You got the Stay Ending.")
        StayEnding = True
        userinput = input("Would you like to reset? ")
        while True:
            if userinput.lower() == "Yes":
                time.sleep(3)
                intro()
            elif userinput.lower() == "No":
                print("Farewell. Remember that you can't save.")
                quit()
            else:
                print("What are you even trying to say?")
                continue

As you can see, I thought that the lower function makes it so that if it is capitalized Yes, then it could make it not capitalized. And functions well but it doesn't work. I tried using the "or" but it doesn't work either. The or works fine for the if but it doesn't wok at the elif. Can anyone help me and tell me where or what am I doing wrong?

I tried using methods, it doesn't work. lower() doesn't work, "or" statement doesn't work. And I just can't risk making my program case-sensitive.

  • _And I just can't risk making my program case-sensitive_ Then why on earth are you using a case-sensitive comparison with "Yes"?!? – John Gordon Jun 14 '23 at 14:30
  • 1
    There is no need to call intro() recursively, and good reasons not to. You can restructure your intro() method to simply loop. – jarmod Jun 14 '23 at 14:32
  • Yeah, sorry guys, I was not very bright that moment. I am confirmed stupid. – Arkan Gaming Jun 18 '23 at 11:17

2 Answers2

1
if userinput.lower() == "Yes":

that is comparing "yes" AND "Yes"

It will never work, as the second term starts with a capital letter.

Either

if userinput.lower() == "yes": 

or

if userinput.lower() == "Yes".lower():

will do the trick

1

You just need to change each of the strings in your if statements to be all lowercase.

if userinput.lower() == "stay":
...
if userinput.lower() == "yes":
...
elif userinput.lower() == "no":
Wilson
  • 399
  • 2
  • 10