-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptionhandling.py
More file actions
37 lines (34 loc) · 1.19 KB
/
Copy pathexceptionhandling.py
File metadata and controls
37 lines (34 loc) · 1.19 KB
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
# 1. Write a program to make a basic calculator for kids in
# super market so that they may verify their calculation using Exceptional Handling. This program must
# have all four arithmetic operations.
def basicCalculator():
print("BASIC CALCULATOR")
try:
choice = int(input("Choose your operation number \n 1) + \n 2) - \n 3) / \n 4) * \n"))
num1 = eval(input("Enter num1"))
num2 = eval(input("Enter num2"))
if type(num1) and type(num2) is not int:
raise TypeError("Numbers can only be integer or float")
if choice == 1:
result = num1 + num2
print(result)
elif choice == 2:
result = num1 - num2
print(result)
elif choice == 3:
result = num1 / num2
print(result)
elif choice == 4:
result = num1 * num2
print(result)
else:
print("Invalid operation choice")
except ZeroDivisionError:
print("Division by zero is not allowed")
except TypeError as e:
print(e)
except Exception:
print("Please Enter valid input")
finally:
print("Program Complete")
basicCalculator()