Skip to content

Commit a214502

Browse files
Add files via upload
0 parents  commit a214502

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

main.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#attempting to make a simple calculator
2+
3+
#this is the function to add integer
4+
def addition(x,y):
5+
return x + y
6+
#function to substract
7+
def substraction(x,y):
8+
return x - y
9+
#function to multiply
10+
def multiplication(x,y):
11+
return x * y
12+
#function to divide
13+
def divide(x,y):
14+
return x / y
15+
16+
print("select your operator")
17+
print("1 for addition")
18+
print("2 for substraction")
19+
print("3 for multiplication")
20+
print("4 for divition")
21+
22+
while True:
23+
choice = input("choose an operator(1/2/3/4/): ")
24+
25+
if choice in ("1", "2", "3", "4"):
26+
num1 = float(input("input a number: "))
27+
num2 = float(input("input another number: "))
28+
29+
if choice == "1":
30+
print(num1, "+", num2, "=", addition(num1, num2))
31+
elif choice == "2":
32+
print(num1, "-", num2, "=",substraction(num1, num2))
33+
elif choice == "3":
34+
print(num1, "*", num2, "=", multiplication(num1, num2))
35+
elif choice == "4":
36+
print(num1,"/", num2, "=", divide(num1, num2))
37+
38+
next = input("want to calculate again? ")
39+
if next == "no":
40+
break
41+
else:
42+
print("invalid input, try again")
43+
44+

0 commit comments

Comments
 (0)