0

When I put in line 7 or the code doesn't work as intended. Can someone please tell me the reason for that?

# x = int(input("Insert price for your product :"))
x=100
print ("Does your product include taxes?")
# answer = input(" yes or no ")
answer = "no"
if answer == "yes" or "Yes" or "YES":
    print ("final price is : ", x, "\n the tax is :" ,x*0.17)
elif answer == "no":
     print ("final price is : ", x*1.17, "\n the taxes is ", x*0.17)
else:
    print ("Your answer is not according to the dictionnary - try again")

I expect that any input for the word YES will work for the if in the code.

Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251
  • "The code is destroyed" ??? –  Dec 24 '22 at 10:19
  • Proofread your question and improve it. It is barely intelligible. (Also proofread your code.) –  Dec 24 '22 at 10:21
  • Does this answer your question? [python if statement evaluation with multiple values](https://stackoverflow.com/questions/26228747/python-if-statement-evaluation-with-multiple-values) – Clasherkasten Dec 24 '22 at 10:23

3 Answers3

0

Try:

if answer in ["yes","Yes","YES"]:
            OR
if answer == "yes" or answer=="Yes" or answer=="YES":

Instead of.

if answer == "yes" or "Yes" or "YES":
Yash Mehta
  • 2,025
  • 3
  • 9
  • 20
0

instead of using if answer == "yes" or "Yes" or "YES":. you should try

if answer == "yes" or answer == "Yes" or answer == "YES":.

OR use python built-in method called lower(), so that you can lowercase your input

x = int(input("Insert price for your product :"))

print ("Does your product include taxes?")
answer = input(" yes or no ").lower()
if answer == "yes":
    print ("finel price is : ", x, "\nthe tax is :" ,x*0.17)
elif answer == "no":
     print ("finel price is : ", x*1.17, "\nthe taxes is ", x*0.17)
else:
    print ("Your answer is not according to the dictionary - try agin")
-1

It's an issue with syntax.

if answer == "yes" or "Yes" or "YES":

In this context in Python you need to spell out each time what variable you are using, for example:

if answer == "yes" or answer== "Yes" or answer== "YES":

or you can format it a different way such as:

answer = answer.lower()
if answer == "yes":
    print ("final price is : ", x, "\nthe tax is : " , x*0.17)
elif answer == "no":
    print ("final price is : ", x*1.17, "\nthe tax is : ", x*0.17)
else:
    print ("Your answer is not according to the dictionary - try again")

this solution will change answer to be all lowercase which allows people to also write things such as YeS or yeS. This also keeps the code from looking cluttered.

Martin
  • 1
  • 2