0
Why do I have a syntaxerror?
I've just started learning and decided to solve some problems. I need to define a function with three arguments which will make arithmetic operations. This is my code: def arithmetic(num1, num2, operation): if operation == '+': return num1+num2 elif operation =='-': return num1-num2 elif operation =='*': return num1*num2 elif operation =='/': return num1/num2 else: return("Unknown operation") >>>arithmetic(1, 2, +) syntax error
3 Answers
+ 3
Because you used the actual + operator as an argument of your 'arithmetic' function instead of putting it in quotes.
0
»> arithmetic(1,2, +)
SyntaxError: invalid syntax
It highlights the last bracket
0
how dumb of me. Thank you, man!