Calculator in python using while loop
Calculator
Write a program that performs the tasks of a simple calculator. The program should first take an integer as input and then based on that integer perform the task as given below.
1. If the input is 1, 2 integers are taken from the user and their sum is printed.
2. If the input is 2, 2 integers are taken from the user and their difference(1st number - 2nd number) is printed.
3. If the input is 3, 2 integers are taken from the user and their product is printed.
4. If the input is 4, 2 integers are taken from the user and the quotient obtained (on dividing 1st number by 2nd number) is printed.
5. If the input is 5, 2 integers are taken from the user and their remainder(1st number mod 2nd number) is printed.
6. If the input is 6, the program exits.
7. For any other input, print "Invalid Operation".
Note: Each answer in next line.
Input format:
Take integers as input, in accordance to the description of the question.
Constraints:
Time Limit: 1 ssecond
Output format:
The output lines must be as prescribed in the description of the question.
Sample Input:
3
1
2
4
4
2
1
3
2
7
6
code
while True:
n=int( input() )
if(n == 1):
a = int(input())
b = int(input())
print(a+b)
if(n == 2):
a = int(input())
b = int(input())
print(a-b)
if(n == 3):
a = int(input())
b = int(input())
print(a*b)
if(n == 4):
a = int(input())
b = int(input())
Print(a/b)
if(n == 5):
a = int(input())
b = (input())
print(a%b)
If(n == 6):
exit(0)
if(n < 1 and n > 6):
print("Invalid Operation")
Sample Output:
2
2
5
Invalid Operation
Bhot ache keep it up and do more your best.
ReplyDelete