I am creating a simple calculator with Python as my first "bigger" project. I am trying to use def function and when i am trying to call that function it gives "undefined name" error message.
while True:
print ("Options: ")
print ("Enter '+' to add two numbers")
print ("Enter '-' to subtract two numbers")
print ("Enter '*' to multiply two numbers")
print ("Enter '/' to divide two numbers")
print ("Enter 'quit' to end the program")
user_input = input(": ")
def calculation (argnum1, argnum2):
argnum1 = float (input("Enter your fist number: "))
argnum2 = float (input("Enter your second number: "))
number = argnum1
number = argnum2
result = argnum1 + argnum2
print (result)
print("-"*25)
return number
return result
if user_input == "quit":
break
elif user_input == "+":
calculation (argnum1, argnum2)
I expect the output of argnum1 + argnum2 result.
calculation (argnum1, argnum2)without having definedargnum1, argnum2. This way, you are going to getNameError: name 'argnum1' is not defined.