Skip to content

Commit 1464523

Browse files
committed
added calculator susccesfully
1 parent d5deb1d commit 1464523

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

python/calculator_.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
def add(P, Q):
2+
# This function is used for adding two numbers
3+
return P + Q
4+
def subtract(P, Q):
5+
# This function is used for subtracting two numbers
6+
return P - Q
7+
def multiply(P, Q):
8+
# This function is used for multiplying two numbers
9+
return P * Q
10+
def divide(P, Q):
11+
# This function is used for dividing two numbers
12+
return P / Q
13+
# Now we will take inputs from the user
14+
print ("Please select the operation.")
15+
print ("a. Add")
16+
print ("b. Subtract")
17+
print ("c. Multiply")
18+
print ("d. Divide")
19+
20+
choice = input("Please enter choice (a/ b/ c/ d): ")
21+
22+
num_1 = int (input ("Please enter the first number: "))
23+
num_2 = int (input ("Please enter the second number: "))
24+
25+
if choice == 'a':
26+
print (num_1, " + ", num_2, " = ", add(num_1, num_2))
27+
28+
elif choice == 'b':
29+
print (num_1, " - ", num_2, " = ", subtract(num_1, num_2))
30+
31+
elif choice == 'c':
32+
print (num1, " * ", num2, " = ", multiply(num1, num2))
33+
elif choice == 'd':
34+
print (num_1, " / ", num_2, " = ", divide(num_1, num_2))
35+
else:
36+
print ("This is an invalid input")

0 commit comments

Comments
 (0)