# Why does it say expected expression

why does it say expected expression for the error i dont even know [edit: what] is wrong

import math
print(“Welcome “+name)
print(””"
Which operation would you like to do:
2 - subtraction
3-multiplication
4 - division
5- exponent
6 - factorial
7 - tax
8 - bmi
9 - tips
10 - temperature
11 - log
12 - cos
13 - sin
14 - tan
“”“)
o = input(”")
if o == “1”:
x = int(input(“What is your first number”))
y = int(input(“What is your second number”))
print(x + y)
elif o == “2”:
x = int(input())
y = int(input())
subtract(x, y)
print(x-y)
elif o == “3”:
x = int(input())
y = int(input())
print(x*y)
elif o == “4”:
x = int(input())
y = int(input())
print(x/y)
elif o == “5”:
x = int(input())
y = int(input())
print(x**y)
elif o == “6”:
x = int(input())
print(math.factorial(x))
elif o == “7”:
price=float(input(“What was the original price of your purchase:”))

if price<0 :
print(“Invalid input”)
quit()

taxrate=float(input(“What is the tax rate of your area (the tax rate of texas is 0.0625):”))
if taxrate>15:
print(“Invalid input”)
quit()
if taxrate<0:
print(“Invalid input”)
quit()
tax=print(price*taxrate)
total=float(total=(tax+price))
print(total)

elif o == “8”:
h=float(input("Enter your height in meters: "))
w=float(input("Enter your Weight in Kg: "))

BMI=w/(h*h)
print("BMI Calculated is: ",BMI)

if(BMI>0):
if(BMI<=16):
print(“You are very underweight”)
elif(BMI<=18.5):
print(“You are underweight”)
elif(BMI<=25):
print(“Congrats! You are Healthy”)
elif(BMI<=30):
print(“You are overweight”)
else:
print(“You are very overweight”)
else:
print(“invalid input”)
elif o == “9”:
bill = float(input(“What is the total bill? \$”))
print (“So you need to pay \$” + str(bill) + “.”)
tipping_amount = int(input("What percentage would you like to tip? 5, 10, or 20% ? "))
print ("So, if you were to tip " + str(tipping_amount) + “…”)
people = int(input("How many people are you splitting the cost with? “))
bill_with_tip = tipping_amount/100 * bill + bill
bill_per_person = bill_with_tip / people
final_amount = round(bill_per_person, 2)
print (“Each person should pay \$” + str(final_amount) + " each.”)

elif o == “10”:

elif o == “11”:
x = int(input())
print(math.log(x))

elif o == “12”:
x = int(input())
math.cos(x)

elif o == “13”:
x = int(input())
print(math.sin(x))

elif o == “14”:
x = int(input())
y = int(input())
print(math.tan(x))
all the elif statements 8 and after all say expected expression idk why

can you show a screenshot of the error

hi @muzeD1 can you post a link to your repl so we can see the error?

I think it might be something to do with the quotes as they don’t look like the correct ones. Has the code been copied and pasted from a Word document / PDF for example?

I’m assuming the replit in question is located at calculator - Replit. From looking at lines 58 and beyond, your indentation is probably at fault.

For example, lines 90-99:

``````elif o == "9":
bill = float(input("What is the total bill? \$"))
print ("So you need to pay \$" + str(bill) + ".")
tipping_amount = int(input("What percentage would you like to tip? 5, 10, or 20% ? "))
print ("So, if you were to tip " + str(tipping_amount) + "...")
people = int(input("How many people are you splitting the cost with? "))
bill_with_tip = tipping_amount/100 * bill + bill
bill_per_person = bill_with_tip / people
final_amount = round(bill_per_person, 2)
print ("Each person should pay \$" + str(final_amount) + " each.")
``````

Python is expecting an expression for this `elif` block, but because the subsequent code isn’t indented, there is no expression, and you get an error. For this example, the correct way to program your tips block would be:

``````elif o == "9":
bill = float(input("What is the total bill? \$"))
print ("So you need to pay \$" + str(bill) + ".")
tipping_amount = int(input("What percentage would you like to tip? 5, 10, or 20% ? "))
print ("So, if you were to tip " + str(tipping_amount) + "...")
people = int(input("How many people are you splitting the cost with? "))
bill_with_tip = tipping_amount/100 * bill + bill
bill_per_person = bill_with_tip / people
final_amount = round(bill_per_person, 2)
print ("Each person should pay \$" + str(final_amount) + " each.")
``````

Hopefully that helps! In the future, I would highly recommend linking your repl so we can be super sure we are looking at the same code + error messages

2 Likes

um i tried it and it made more errors saying unexpected indent
main.py - calculator - Replit

Hi @muzeD1

Yes there are still incorrect indents in your code.

In this example line 50-65 need to be indented to line up with line 48 as a minimum.

You might find more indent problems. The error message I saw when I ran the code said the indent error was line 70. I worked backwards from there until I found the line `elif o == "7":` - this line was correct so everything between it and line 70 had an issue.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.