Create a simple calculator
Level: Intermediate (score: 3)
In this Bite you will create a simple calculator. It takes a string of num1 operator num2
which you convert into its calculation returning its result. Complete simple_calculator
to that end supporting +
, -
, *
and /
("true" division so 2/3 = .66 rather than 0).
So passing '2 * 3'
into the function it would return 6
, '2 + 6'
results in 8
, '-5 * -11'
= 55
and lastly '1 / 5'
= 0.20
.
For any bad data passed into the function (e.g. a / 3
, 2 * b
, 1 ^ 2
, etc), you should raise a ValueError
.
Good luck and have fun!