Skip to content

Commit 0f12786

Browse files
committed
Update Exceptions
1 parent f13d6c2 commit 0f12786

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

Python/Exceptions/Main.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
try:
2+
number = int(input("Enter a number: "))
3+
print(number)
4+
5+
except:
6+
print("Invalid Input, please enter number!")
7+
8+
9+
x = 0
10+
11+
try:
12+
print(1/x)
13+
14+
except ZeroDivisionError:
15+
print("Cannot divide by zero!")
16+
17+
18+
var_dict = {"average" : "5.0"}
19+
20+
try:
21+
print(f"Average is {var_dict['average']}")
22+
23+
except KeyError:
24+
print("Key not found in dictionary!")
25+
26+
except TypeError:
27+
print("You cannot divide string values!")
28+
29+
else:
30+
print("No exceptions occurred.")
31+
32+
finally:
33+
print("Execution completed.")
34+

Python/Exceptions/TryAndCatch.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)