-1
salary = int(input("How much is your salary: "))
saving = int(input("How much is your saving: "))
if (salary<30000) or (saving<4000):
    print("You are eligible to get free ticket.")
    choice = input("Do you need some help? ")
    if choice == "yes" or "yeah" or "y":
        print("Well then congrats! You get a free ticket.")
    elif choice == "no" or "nope" or "n":
        print("Thank you for answering. ")
else:
    print("Proceed ahead!!")

So here when I enter yes or no I am not getting the answer I am expecting based on the conditions. Can anybody tell me the reason, please? Thank you.

  • Welcome to StackOverflow! I see you're a new contributor, so I advise you to check out [How to ask a good question](https://stackoverflow.com/help/how-to-ask) and [How to create a minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). Can you elaborate on what the expect and actual behavior are for your script? Also, note that `if choice == "yes" or "yeah" or "y":` is the same as `if (choise == "yes") or bool("yeah") or bool("y"):` – Brian61354270 Apr 04 '20 at 17:33

2 Answers2

0

You need to specify every condition when comparing strings in python. Use the following code.

salary = int(input("How much is your salary: "))
saving = int(input("How much is your saving: "))
if (salary<30000) or (saving<4000):
    print("You are eligible to get free ticket.")
    choice = input("Do you need some help? ")
    if choice == "yes" or choice == "yeah" or choice == "y":
        print("Well then congrats! You get a free ticket.")
    elif choice == "no" or choice == "nope" or choice == "n":
        print("Thank you for answering. ")
else:
    print("Proceed ahead!!")

If you do print("yes") it just prints the string. But if you do print(choice == "yes") prints out True. Which is what you need when doing if statements.

David Teather
  • 568
  • 5
  • 15
0

You have mistakes at the if statement. It should be:

if choice == "yes" or choice == "yeah" or choice == "y"

or

if choice in ['yes', 'yeah', 'y']
Binh
  • 1,143
  • 6
  • 8