+ 2

Please what's wrong with the option 3, 4, 5 and else of this code? I keep getting NameError.

# IT HAS BEEN CORRECTED #welcome statement print("This is a basic calculator, fill in each field and press the enter button to proceed") print("What operation do you want to perform?") #operation print("""1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Exponent""") #function definition def add(x, y): return x+y def sub(x, y): return x-y def mul(x, y): return x*y def div(x, y): return x/y def expo(x, y): return x**y #User input operation = input("Enter operator: ") n1 = float(input("Enter first number: ")) n2 = float(input("Enter second number: ")) if operation == "1": print(n1, '+' , n2, '=', add(n1, n2)) elif operation == '2': print(n1, '-', n2, '=', sub(n1, n2)) elif operation == '3': print(n1, '*', n2, '=', mul(n1, n2)) elif operation == '4': print(n1, '/', n2, '=', div(n1, n2)) elif operation == '5': print(n1, '**', n2, '=', expo(n1, n2)) else: print("Please enter a valid operator")

29th Mar 2022, 8:18 PM
David Michael
David Michael - avatar
3 Respostas
+ 2
You have typo error in opearton == '3' use elif operation == '3': look fine remainings..
29th Mar 2022, 8:30 PM
Jayakrishna 🇮🇳
+ 2
Jayakrishna🇮🇳 thank you man I didn't see that, really love this community.
29th Mar 2022, 8:35 PM
David Michael
David Michael - avatar
+ 1
You're welcome..
29th Mar 2022, 8:49 PM
Jayakrishna 🇮🇳