A Calculator Function
In a file called calculator_function.py
, write a calc
function that executes simple arithmetic operations, as follows:
- The function takes 3 arguments: number, operator (string), number
- It supports the four basic operations:
+
,-
,*
,/
- It returns a number that is the result of the requested calculation
Mentoring topics
Discuss what happens when a division by zero occurs, or when the function arguments have invalid values, such as an operator that is not one in the allowed list.
Future exercises will show how to cope with such situations.
Test code
To validate your code, download the test code below and run it as explained on the Hello, Python exercise page.
Test code: calculator_function_test.py