# Invalid syntax on if statement

So I am making a calculator in python as part of a school homework project and while I am aware it is not quite finished, I have come across an invalid syntax in my code on line 22. it is saying that the bracket on this line is an invalid syntax. Can someone help me out with this please? The rest I should be able to do myself.

print(“Calculator”)
print(" ")

return a + b

def Minus(a,b):
return a - b

def Divide(a,b):
return a / b

def Multiply(a,b):
return a * b

while True:
result =0
value1 =0.0
while True:
value1 = float(input("value: "))
operator = chr(input("operator: ")
if value1 == 0.0:
print(result)
if operator == ‘+’:
if operator == ‘-’:
result -= Minus(result,value1)
if operator == ‘/’:
result /= Divide(result,value1)
if operator == ‘*’:
result *= Multiply(result,value1)
else:
print(result)

So I am making a calculator in python as part of a school homework
project and while I am aware it is not quite finished, I have come
across an invalid syntax in my code on line 22. it is saying that the
bracket on this line is an invalid syntax. Can someone help me out with
this please? The rest I should be able to do myself.
[…]

It would be helpful if you also pasted in the entire error message. That
will usually pinpoint exactly where Python was unhappy. (Occasionally
the actual error is earlier in the code, but regardless the rrror
message is important in finding the mistake.)

That said, your if-statements look syntacticly ok to my eye.

I would remark that for reasons of getting the logic correct you may
want an else: after the first if, and elifs instead of ifs for the
second and following operator tests.

while True:
result =0
value1 =0.0
while True:
value1 = float(input("value: "))
operator = chr(input("operator: ")
if value1 == 0.0:
print(result)
if operator == ‘+’:
if operator == ‘-’:
result -= Minus(result,value1)
if operator == ‘/’:
result /= Divide(result,value1)
if operator == ‘*’:
result *= Multiply(result,value1)
else:
print(result)

Cheers,
Cameron Simpson cs@cskk.id.au

Sometimes the interpreter can’t tell where the syntax error is until it
reaches the next line, especially errors involving brackets. This is one
of those cases. You have:

``````operator = chr(input("operator: ")
if value1 == 0.0:
...
``````

Notice the call to `chr()` has two opening round brackets but only one
closing bracket. The interpreter can’t tell that’s wrong until it
reaches the “if” on the next line, so that’s where it reports the error.