Calculator

Report a typo

Let's write a simple calculator!

It will read 3 lines:

  • the first number
  • the second number
  • the arithmetic operation.

Numbers are floats!

The output is the result of the following: first_number operation second_number.

Operations are: +, -, /, *, mod, pow, div.
mod — modulo operation, i.e. the remainder of the division first_number % second_number,
pow — exponentiation, the first number will be the base and the second — the power: first_number ** second_number,
div — integer division first_number // second_number.

Note that if the second number is 0 and you want to perform any of the operations /, mod, or div, the calculator should say "Division by 0!"

If you have too many elif branches, you may consider another approach, for example, break the code into smaller functions. Since you don't know how to do it yet, ignore the code style error about the number of elif branches.

Sample Input 1:

5.0
0.0
mod

Sample Output 1:

Division by 0!

Sample Input 2:

-12.0
-8.0
*

Sample Output 2:

96.0

Sample Input 3:

5.0
10.0
/

Sample Output 3:

0.5
Write a program in Python 3
# put your python code here
___

Create a free account to access the full topic