-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathcalculator-function.py
More file actions
46 lines (36 loc) · 1.13 KB
/
calculator-function.py
File metadata and controls
46 lines (36 loc) · 1.13 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
#function add
def add():
n1 = float(input("Enter first number: "))
n2 = float(input("Enter second number: "))
return n1+n2
#function substract
def subtract():
n1 = float(input("Enter first number: "))
n2 = float(input("Enter second number: "))
return n1 - n2
#function multiply
def multiply():
n1 = float(input("Enter first number: "))
n2 = float(input("Enter second number: "))
return n1 * n2
#function dividen
def divide():
n1 = float(input("Enter first number: "))
n2 = float(input("Enter second number: "))
return n1 / n2
#add input
if __name__ == "__main__":
while True:
choice = input("1. Add\n2. Subtract\n3. Multiply\n4. Divide\n5. Exit\n")
if choice == '1':
print("The sum is:",add())
elif choice == '2':
print("The difference is:",subtract())
elif choice == '3':
print("The product is:",multiply())
elif choice == '4':
print("The quotient is:",divide())
elif choice == '5':
break
else:
print("Enter correct choice!!")