Simple calculator X97965


Statement
 

pdf   zip

Write a function @calculator(a, b, operator)@ to compute simple arithmetic expressions. The function receives as arguments two numbers aa and bb and a character @operator@ that is always either ’+’, ’-’ or ’*’. The function has to return either the addition a+ba + b, substraction aba - b or the multiplication a*ba*b depending on the actual value of @operator@.

Sample session

Sample session
>>> calculator(3.2, 5, '+')
8.2
>>> calculator(2, 3 + 1/2, '-')
-1.5
>>> calculator(1/2, 4, '*') - calculator(1, 1, '+')
0.0
Information
Author
ProAl
Language
English
Official solutions
Python
User solutions
Python