# Calculator program in Python

In the preceding article we have written a program to determine whether a given year is a leap year. Now we will look at a program to implement basic common calculator utility functions for user-given input numbers for whichever operation is selected. If we imagine a calculator and it’s working, we understand that there needs to be choice for entering numbers, for selecting a particular option out of the ones available. Since our program is limited in function, we will also provide an error message upon entering invalid choices.

### Implementation of Calculator program in Python

We will implement the basic operations such as addition, subtraction, multiplication and division. However, this program logic can be expanded in the future if required to incorporate more operations by either defining the working or by utilizing the math library functions which would prove to be very useful for such a case. At it’s most ultimate, it could be packed to work as a GUI calculator application.

```#Python Simple Calculator Implementation
import sys
2.Subtract
3.Multiply
4.Division
""")
choice=int(input("Select Operation  from 1, 2, 3 or 4 "))
if choice not in (1,2,3,4):
print("Invalid Choice")
sys.exit()
a = int(input("Enter First Number: "))
b=int(input("Enter Second Number: "))
if choice == 1:
res= a + b
elif choice == 2:
res= a - b
elif choice == 3:
res= a * b
else:
res=a/b
print("Result is", res)
```
``````Output:
2.Subtract
3.Multiply
4.Division

Select Operation  from 1, 2, 3 or 4: 4
Enter First Number: 22
Enter Second Number: 7
Result is 3.142857142857143