-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathcalculator.py
More file actions
40 lines (38 loc) · 889 Bytes
/
calculator.py
File metadata and controls
40 lines (38 loc) · 889 Bytes
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
# To make calcultor
print("1.Addiion")
print("2.Subtraction")
print("3.Multiplicaton")
print("4.Division")
valid = False
while not valid:
try:
num1 = float(input("Enter the first number"))
valid = True
except ValueError:
print('Input not valid, please retry')
valid = False
while not valid:
try:
num2 = float(input("Enter the second number"))
valid = True
except ValueError:
print('Input not valid, please retry')
valid = False
while not valid:
choice = int(input("Enter a choice: 1,2,3,4"))
if choice not in [1,2,3,4]:
print("Invalid choice, please retry")
else:
valid = True
if choice == 1:
sum = num1 + num2
print(sum)
elif choice == 2:
sub = num1 - num2
print(sub)
elif choice == 3:
mul = num1 * num2
print(mul)
elif choice == 4:
div = num1 / num2
print(div)