-4

Everytime I run my code it says that y is not defined. Why?

def main():
     x=str(input("enter first number : "))
     ab=(input("enter operator : "))
     z=str(input("enter second number : "))

if (ab) ==("+"):
     print(float(x)+float(z))
elif (ab) ==("-"):
     print(float(x)-float(z))
elif (ab) ==("/"):
     print(float(x/float(z))
if (ab) ==("*"):
           print(float(x*float(z))

closed as off-topic by joan, Milliways, Ghanima Dec 22 '18 at 10:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – joan, Milliways, Ghanima
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Not a Pi specific question. There is no y in the code. The code does not compile. – joan Dec 22 '18 at 8:57
  • It's not going to do you any favours if you post syntactically incorrect python that doesn't even demonstrate the problem you're claiming exists. raspberrypi.stackexchange.com/help/how-to-ask – Dougie Dec 22 '18 at 9:36
1

You missed a couple of ")"

def main():
 x=str(input("enter first number : "))
 ab=(input("enter operator : "))
 z=str(input("enter second number : "))

 if (ab) ==("+"):
      print(float(x)+float(z))
 elif (ab) ==("-"):
      print(float(x)-float(z))
 elif (ab) ==("/"):
      print(float(x/float(z)))  

 if (ab) ==("*"):
      print(float(x)*float(z))
  • To the contrary it has too many parentheses. – Milliways Dec 22 '18 at 9:07
  • Ah I saw print () and thought python3? – Craig Dec 22 '18 at 9:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.