Skip to content

Commit c4fd4a6

Browse files
author
evans1989
committed
Create 1001S02E03_calculator.py
1 parent c8b8068 commit c4fd4a6

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

1901060026/1001S02E03_calculator.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Filename : calculator.py
2+
# Author by : Evans
3+
4+
# Define the function
5+
def add (x , y):
6+
"""add"""
7+
return x + y
8+
9+
def subtract(x , y):
10+
"""subtract"""
11+
return x - y
12+
13+
def multiply(x , y):
14+
"""muliply"""
15+
return x * y
16+
17+
def divide(x , y) :
18+
"""divide"""
19+
return x / y
20+
21+
# User input
22+
print("Choose function")
23+
print("1.Add")
24+
print("2.Subtract")
25+
print("3.Multiply")
26+
print("4.Divide")
27+
28+
choice = input("Input your choice(1/2/3/4):")
29+
30+
num1 = float(input("Input the first number:"))
31+
num2 = float(input("Input the second number"))
32+
33+
if choice == '1' :
34+
print(num1,"+",num2,"=",add(num1,num2))
35+
36+
elif choice =='2' :
37+
print(num1,"-",num2,"=",subtract(num1,num2))
38+
39+
elif choice =='3' :
40+
print(num1,"*",num2,"=",multiply(num1,num2))
41+
42+
elif choice =='4' :
43+
print(num1,"/",num2,"=",divide(num1,num2))
44+
45+
else:
46+
print("Error")

0 commit comments

Comments
 (0)