0

Having trouble understanding what's wrong with my code. It keeps printing out the additional_discount value regardless of the input for student_status. seen here is the code

def discount(x):
    return x * .9

def additional_discount(x):
    return discount(x) * .95

og_price = float(input("Please enter your current price in dolalrs: "))
student_status = str(input("Are you a student? "))

if student_status == "Yes" or "yes"
    print("Your price is ", additional_discount(og_price))
elif student_status == "No" or "no":
    print("Your price is ", discount(og_price))
else:
    print("I'm sorry, that is an invalid response")

Thank you!

RealRageDontQuit
  • 405
  • 4
  • 17
  • Stackoverflow encourages including code not links to code so others can easily experiment. – DarrylG Jan 05 '20 at 17:01
  • Your problem is you are incorrectly comparing a value to multiple values (i.e. student_status == "Yes" or "yes" is incorrect). Use if student_status == "YES" or student_status == "yes". Or more simply: if student_status.lower() == "yes" – DarrylG Jan 05 '20 at 17:04
  • Having had a very quick look at your code, you only specify half of the or statement - ‘or ‘yes’’ rather than or x == ‘yes’. Just or ‘yes’ will always evaluate to true. – JayBe Jan 05 '20 at 17:07

1 Answers1

0

You should change your if-condition:

if student_status in ['Yes', 'yes']:
  do something
elif student_status in ['No', 'no']:
  do

The statement you use is if student_status == 'Yes' or 'yes'. It means student_status == 'Yes' or 'yes'. The boolean value for 'yes' is True, so the condition always holds.

You can refer to here for the boolean value of python objects.

youkaichao
  • 1,938
  • 1
  • 14
  • 26
  • Thank you for the great response. I don't know the classes yet but want to ask why "Yes" gets a Boolean value of true. Is it because everything has a default value of true unless it goes against a specified condition? – PythonTrain Jan 05 '20 at 17:22
  • A string object is true unless it is an empty string ``''``. – youkaichao Jan 05 '20 at 17:23