avatar Bite 159. Create a simple calculator

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!

Login and get coding
go back Intermediate level
Bitecoin 3X

Will you be Pythonista #126 to crack this Bite?
Resolution time: ~24 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 2.57 on a 1-10 difficulty scale.
» You can do it! 😌

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help