0

I'm trying to code some kind of multiple-choice kinda game, but no matter the input, the if-statement is always triggered, even if the input is d or D.

It might be an obvious mistake, but I'm an absolute beginner at programming, so I really hope you guys can help me point out what I've done wrong.

My code looks like this:

answer = input("Do you want to do something (C) or something else (D)? [C/D]")

if answer == "c" or "C":
    print ("You typed", answer)
    time.sleep(2)
    print ("You can now do something")
    time.sleep(2)


elif answer == "d" or "D":
    print ("You typed", answer)
    time.sleep(2)
    print ("You can now do something else")
    time.sleep(2)


else:
    Exit()
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Luke_Leon
  • 23
  • 4

2 Answers2

1
answer = input("Do you want to do something (C) or something else (D)? [C/D]")

if answer == "c" or answer == "C": # Here is your mistake
    print ("You typed", answer)
    time.sleep(2)
    print ("You can now do something")
    time.sleep(2)


elif answer == "d" or answer == "D":  # also here
    print ("You typed", answer)
    time.sleep(2)
    print ("You can now do something else")
    time.sleep(2)


else:
    Exit()
Mohit Solanki
  • 2,122
  • 12
  • 20
1

Python works different from the english language.

if answer == "c" or "C": should be if answer == "c" or answer == "C": Similarly for D.

This question has been previously answered here. You can read more about logical OR here.

sP_
  • 1,738
  • 2
  • 15
  • 29