-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program1.py
69 lines (55 loc) · 1.23 KB
/
Program1.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# WAP to show functionality of a basic calculator using functions.
def add(P, Q):
# This function is used for adding two numbers
return P + Q
def subtract(P, Q):
# This function is used for subtracting two numbers
return P - Q
def multiply(P, Q):
# This function is used for multiplying two numbers
return P * Q
def divide(P, Q):
# This function is used for dividing two numbers
return P / Q
# Now we will take inputs from the user
print("""Please select the operation.")
print(a. Add)
print(b. Subtract)
print(c. Multiply)
print(d. Divide""")
choice = input(
"Please enter choice (a/ b/ c/ d): "
)
num_1 = int(
input(
"Please enter the first number: "
)
)
num_2 = int(
input(
"Please enter the second number: "
)
)
if choice == 'a':
print(
num_1, " + ", num_2, " = ",
add(num_1, num_2)
)
elif choice == 'b':
print(
num_1, " - ", num_2, " = ",
subtract(num_1, num_2)
)
elif choice == 'c':
print(num_1, " * ", num_2, " = ",
multiply(num_1, num_2)
)
elif choice == 'd':
print(
num_1, " / ", num_2, " = ",
divide(num_1, num_2)
)
else:
print(
"This is an invalid input"
)