Skip to content

Commit b239c4c

Browse files
authored
Simple Calculator by Using Functions
1 parent 229f8d6 commit b239c4c

1 file changed

Lines changed: 49 additions & 1 deletion

File tree

README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,49 @@
1-
# pythonprogram
1+
# pythonprogram
2+
# Program make a simple calculator
3+
4+
# This function adds two numbers
5+
def add(x, y):
6+
return x + y
7+
8+
# This function subtracts two numbers
9+
def subtract(x, y):
10+
return x - y
11+
12+
# This function multiplies two numbers
13+
def multiply(x, y):
14+
return x * y
15+
16+
# This function divides two numbers
17+
def divide(x, y):
18+
return x / y
19+
20+
21+
print("Select operation.")
22+
print("1.Add")
23+
print("2.Subtract")
24+
print("3.Multiply")
25+
print("4.Divide")
26+
27+
while True:
28+
# Take input from the user
29+
choice = input("Enter choice(1/2/3/4): ")
30+
31+
# Check if choice is one of the four options
32+
if choice in ('1', '2', '3', '4'):
33+
num1 = float(input("Enter first number: "))
34+
num2 = float(input("Enter second number: "))
35+
36+
if choice == '1':
37+
print(num1, "+", num2, "=", add(num1, num2))
38+
39+
elif choice == '2':
40+
print(num1, "-", num2, "=", subtract(num1, num2))
41+
42+
elif choice == '3':
43+
print(num1, "*", num2, "=", multiply(num1, num2))
44+
45+
elif choice == '4':
46+
print(num1, "/", num2, "=", divide(num1, num2))
47+
break
48+
else:
49+
print("Invalid Input")

0 commit comments

Comments
 (0)