-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.py
More file actions
26 lines (23 loc) · 860 Bytes
/
calculator.py
File metadata and controls
26 lines (23 loc) · 860 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
#first_no = input("Enter the first number: ")
#second_no = input("Enter the second number: ")
#operation = input("Choose the operation (+, -, *, /): ")
while True:
try:
first_no = int(input("Enter the first number: "))
second_no = int(input("Enter the second number: "))
except ValueError:
print("Numbers were invalid")
continue
else:
break
operation = input("Choose the operation (+, -, *, /): ")
if operation == '+':
print("The answer is {}".format((int(first_no) + int(second_no))))
elif operation == '-':
print("The answer is {}".format((int(first_no) - int(second_no))))
elif operation == '*':
print("The answer is {}".format((int(first_no) * int(second_no))))
elif operation == '/':
print("The answer is {}".format((int(first_no) / int(second_no))))
else:
print("Operation is invalid")