-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basic Calculator
50 lines (40 loc) · 1.22 KB
/
Basic Calculator
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# python 1st project basic calculator
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
return x / y
print("Let's Calculate")
while True:
print("Choose an operation:")
print("a. Add")
print("b. Subtract")
print("c. Multiply")
print("d. Divide")
print("e. Exit")
choose = input("Choose an option to calculate (a-e): ")
if choose == 'e':
print("I hope that your problem solved.B-Bye")
break
if choose in ('a', 'b', 'c', 'd'):
num1 = float(input("Enter the num 1 : "))
num2 = float(input("Enter the num 2: "))
if choose == 'a':
result = add(num1, num2)
operator = "+"
elif choose == 'b':
result = subtract(num1, num2)
operator = "-"
elif choose == 'c':
result = multiply(num1, num2)
operator = "*"
elif choose == 'd':
result = divide(num1, num2)
operator = "/"
print(f"{num1} {operator} {num2} = {result}")
else:
print("Invalid input. Please try again.")
#Thanks for visiting my profile I hope that the code will help you