Skip to content

Commit 042218f

Browse files
Add files via upload
1 parent 70bc20b commit 042218f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

python-calculator/PyCal/calculator.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This function performs additiion
2+
def add(a, b):
3+
return a + b
4+
# This function performs subtraction
5+
def subtract(a, b):
6+
return a - b
7+
# This function performs multiplication
8+
def multiply(a, b):
9+
return a * b
10+
# This function performs division
11+
def divide(a, b):
12+
return a / b
13+
14+
15+
print("Select an operation.")
16+
print("+")
17+
print("-")
18+
print("*")
19+
print("/")
20+
# User input
21+
choice = input("Enter operator to use:")
22+
A = int(input("Enter first number: "))
23+
B = int(input("Enter second number: "))
24+
if choice == '+':
25+
print(A,"+",B,"=", add(A,B))
26+
elif choice == '-':
27+
print(A,"-",B,"=", subtract(A,B))
28+
elif choice == '*':
29+
print(A,"*",B,"=", multiply(A,B))
30+
elif choice == '/':
31+
if B==0:
32+
print("Divided by zero Error")
33+
print(A,"/",B,"=", divide(A,B))
34+
else:
35+
print("Invalid input")

0 commit comments

Comments
 (0)