-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject_6.py
50 lines (41 loc) · 1.46 KB
/
Project_6.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#Question Statement
"""Creating a CALCULATOR"""
from os import system
def calculation(num1,num2,op):
if op=="+":
return num1+num2
if op=="-":
return num1-num2
if op=="*":
return num1*num2
if op=="/":
return num1/num2
# num_1=int(input("Enter your 1st number: "))
# print("Operand List: \n+\n-\n*\n/")
# cal=input("Select an operand from the list above: ")
# num_2=int(input("Enter your next number: "))
# res=calculation(num_1,num_2,cal)
# print(res)
choice="n"
while choice:
if choice=="n":
num_1=int(input("Enter your 1st number: "))
print("Operand List: \n+\n-\n*\n/")
cal=input("Select an operand from the list given above: ")
num_2=int(input("Enter your next number: "))
res=calculation(num_1,num_2,cal)
print(f'{num_1}{cal}{num_2}={res}')
choice=input(f"Enter 'y' to continue calculation with {res} or 'n' to start new calculation or 'x' to exit: ")
elif choice=='y':
num_1=res
cal=input("Select an operand from the list given above: ")
num_2=int(input("Enter your next number: "))
res=calculation(num_1,num_2,cal)
print(res)
choice=input(f"Enter 'y' to continue calculation with {res} or 'n' to start new calculation or 'x' to exit: ")
elif choice=='x':
print("exit calculator")
break
else:
print("something is wrong with your input")
break