When I execute and run the code the program doesn't seem to store the c input, therefore not continuing the code to perform the rest of the calculator function.
def calc():
print("Press 1 for addition")
print("Press 2 for subtraction")
print("Press 3 for multiplication")
print("Press 4 for division")
c = input()
if c == 1:
print("Enter a number")
x = input()
print("Enter another number")
y = input()
return x + y
elif c == 2:
print("Enter a number")
x = input()
print("Enter another number")
y = input()
return x - y
elif c == 3:
print("Enter a number")
x = input()
print("Enter another number")
y = input()
return x * y
elif c == 4:
print("Enter a number")
x = input()
print("Enter another number")
y = input()
return x / y
calc()
I've now improved the code but can't seem to get the indentation right and it seems that the return function on each type of math that is being performed is 'outside function'
def calc():
print("Press 1 for addition")
print("Press 2 for subtraction")
print("Press 3 for multiplication")
print("Press 4 for division")
c = int(input())
def get_inputs():
print("Enter a number")
x = int(input())
print("Enter another number")
y = int(input())
return x, y
if c == 1:
x, y = get_inputs()
return x + y #These return functions seem to be an error
elif c == 2:
x, y = get_inputs()
return x - y
elif c == 3:
x, y = get_inputs()
return x * y
elif c == 4:
x, y = get_inputs()
return x / y
calc()