-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3-simple-calculaator.py
More file actions
61 lines (42 loc) · 1.42 KB
/
3-simple-calculaator.py
File metadata and controls
61 lines (42 loc) · 1.42 KB
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
51
52
53
54
55
56
57
58
59
60
61
#Simple calculator
#step:1 all calculation define in function
def add(a,b):
return a+b
def sub(a,b):
return a-b
def multi(a,b):
return a*b
def div(a,b):
if b==0:
return"Error: Zero se divide ni hota"
return a/b
#step:2 Now, display the Symbolls (menu type)-- which type of operation can performed by user
#It can show every operations after then user exit value click then terminate the program
while True:
print("\n*** Simple Calculator ***")
print("1. Addition (+)")
print("2. Subtraction (-)")
print("3. Multiplication (*)")
print("4. Division (/)")
print("5. Exit")
choice=input("Enter Your choice (1-5)")
if choice == "5":
print("Exiting... GoodBye")
break
if choice in ("1","2","3","4"):
try:
num1=int(input("Enter First number: " ))
num2=int(input("Enter First number: " ))
except ValueError:
print("invild input!")
continue
if choice =="1":
print(f"Result: {num1}+{num2}= {add(num1,num2)}")
elif choice =="2":
print(f"Result: {num1}-{num2}= {sub(num1,num2)}")
elif choice =="3":
print(f"Result: {num1}*{num2}= {multi(num1,num2)}")
elif choice =="4":
print(f"Result: {num1}/{num2}= {div(num1,num2)}")
else:
print("invaild choice")