Saturday, 7 September 2013

What is syntax error of this?

What is syntax error of this?

I had written a small console calculator in python:
def calculator(num1=0, num2=0):
conta = input("Type operation(+,x,/ or -:)")
if (conta == "+"):
print("Result:" + repr(num1) + " + " + repr(num2) + " is " +
str(num1 + num2))
elif (conta == "-"):
print("Result:" + repr(num1) + " - " + repr(num2) + " is " +
str(num1 - num2))
elif (conta == "x"):
print("Result:" + repr(num1) + " x " + repr(num2) + " is " +
str(num1 * num2))
elif (conta == "/"):
print("Result: " + repr(num1) + " + " + repr(num2) + " is " +
str(num1 / num2))
else:
print("Result:" + repr(num1) + conta + repr(num2) + " is Are you
Joking?")
try:
num1 = float(input("Type a number:"))
num2 = float(input("Type a number:"))
calculator(num1, num2)
except:
print("Error.")
exit()
It works properly in IDLE Shell. I put:
500.65 + 300 = 700.65
12 joke 12 = Are you Joking?
And then...When I load it from .PY file, It asks a number. I put it. Asks
another. Put it. Asks for operation. I put one. The window closes.
Now I try to run it on Python console. Returns:
SyntaxError in line 1 => Invalid Syntax.
So, what's wrong? What can I do?

No comments:

Post a Comment