-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchapter_07.py
More file actions
54 lines (37 loc) · 1.04 KB
/
chapter_07.py
File metadata and controls
54 lines (37 loc) · 1.04 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# ======== > Types of the errors < ==========
# ======= > Syntax Error < =========
# if x <= 20
# print("x is the smaller than 20")
# ========== > Runtime Error < ==========
# a = 10/0
# print(a)
# ========== > Try and Except Block < =========
# try:
# num = int(input("Enter the Number : "))
# reuslt = 20/num
# print("Reuslt : ", reuslt)
# except ZeroDivisionError:
# print("Cannot Divided by Zero")
# except ValueError:
# print("Invalid value, please enter the number instead of zero or string")
# # finally :
# # print("Execution Finished")
# else:
# print("Your Entered Number : ", num)
# x = 20
# print(x)
# ======== > Rasing Execptions < =============
# age = int(input("Enter the age : "))
# if age <= 0:
# raise ValueError("Age cannot be negative")
# x = 20
# print(x)
# ====== > Custom Error Message < =========
try:
age = int(input("Enter the age : "))
if age <= 0:
raise Exception("Age cannot be negative")
except Exception as e:
print("Error: ", Exception)
x = 20
print(x)