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

8th Dec 2016, 9:37 PM
Ruslan Egorov
Ruslan Egorov - avatar
3 Answers
+ 3
Because you used the actual + operator as an argument of your 'arithmetic' function instead of putting it in quotes.
8th Dec 2016, 9:51 PM
Arthur Busser
Arthur Busser - avatar
0
»> arithmetic(1,2, +) SyntaxError: invalid syntax It highlights the last bracket
8th Dec 2016, 9:38 PM
Ruslan Egorov
Ruslan Egorov - avatar
0
how dumb of me. Thank you, man!
8th Dec 2016, 10:14 PM
Ruslan Egorov
Ruslan Egorov - avatar