-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleCalculator.py
46 lines (35 loc) · 1.2 KB
/
SimpleCalculator.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
def add_nums(num1, num2):
return f"{num1} + {num2} = {num1+num2}"
def sub_nums(num1, num2):
return f"{num1} - {num2} = {num1-num2}"
def mult_nums(num1, num2):
return f"{num1} * {num2} = {num1*num2}"
def div_nums(num1, num2):
if num2 == 0:
return "Invalid output"
else:
return f"{num1} / {num2} = {num1/num2}"
def main():
while True:
chk = input("You want to do calculation (y/n): ")
if chk == "y":
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
op = input("Enter the operation you want to perform: ")
if op == "+":
print(add_nums(num1, num2))
elif op == "-":
print(sub_nums(num1, num2))
elif op == "*":
print(mult_nums(num1, num2))
elif op == "/":
print(div_nums(num1, num2))
else:
print("Please Enter valid operator")
elif chk == "n":
print("Exiting Program")
break
else:
print("Please Enter valid option")
if __name__ == "__main__":
main()