# what's wrong with my simple calculator, it doesn't error and doesn't execute

1566 views
-1

I can't quite figure out why my code won't work.

Whenever I click run, it doesn't follow back with a traceback error, it just says process finished with exit code 0.

I thought it might be the casefold but then when I applied it to `"Y"`. casefold it wouldn't work full stop.

``````def calculate():

operator = input("please select the kind of maths you would like to do")
if operator == "+":

num1 = int(input('Enter first number: '))
num2 = int(input('Enter second number: '))
print('{} + {} ='.format(num1, num2))
print(num1 + num2)

elif operator == "-":

num1 = int(input("enter first number: "))
num2 = int(input("enter second number: "))
print("{} - {} =".format(num1, num2))
print(num1 - num2)

elif operator == "*":

num1 = int(input("enter first number: "))
num2 = int(input("enter second number: "))
print("{} * {} =".format(num1, num2))
print(num1 * num2)

elif operator == "/":

num1 = int(input("enter first number: "))
num2 = int(input("enter second number: "))
print("{} / {} =".format(num1, num2))
print(num1 / num2)

else:
_exit = input("would you like to exit? type Y for YES and N for NO")
if _exit.casefold() == "y":
sys.exit()
else:
calculate()
``````

Did you call the function?

How do you call `calculate`?

add a line at the bottom with no indentation. calculate()

Remove the last `else` statement and add `calculate()` without any indendation at the bottom.

9

Just add `calculate()` at the very end to call the function.

posted this
11

You need to call this `calculate()` function first (at least it's not being executed in your code sample).

``````def calculate()
# func code here

#Exec this function
calculate()
``````

posted this
7

Put function calling `calculate()` at the end without any indent. Your function isn't even getting called, thus giving no error.

posted this

JD