In this python program code, we will learn to form a simple calculator which will perform a basic arithmetic operation such as addition, subtraction, multiplication, and division, depending upon the input given by the user.
Here, we have made a function named calc(n) which will further perform the desired operation.
- Define a function named calc(n).
- In the function, sum “s” and product “p” initialize to 0 and 1 respectively.
- Take two numbers as input from the user, further operations are performed on it.
- For different values of i we will perform different operations and it is passed in the function calc().
- We perform the different operation on the number which is input by the user .
i=int(input("enter for calculation 1. add 2. product 3.subtract 4.divide"))
enter for calculation 1. add 2. product 3.subtract 4.divide 2
enter for calculation 1. add 2. product 3.subtract 4.divide 4