1try:
2 print("I will try to print this line of code")
3except:
4 print("I will print this line of code if an error is encountered")
1try:
2 print("try to run this block")
3except:
4 print("run this bock if there was error in earlier block")
1# taking input from the user
2try:
3 age = int(input("Please enter your age: "))
4 print(age)
5except:
6 print("please enter a number instead! ")
7 print('bye')
8
9
10# if you wanna ask their age until they enter the correct number use While Loop
11while True:
12 try:
13 age = int(input("Please enter your age: "))
14 print(age)
15 except:
16 print("please enter a number instead! ")
17 else:
18 break
19
20
1try:
2 print("I will try to print this line of code")
3except:
4 print("I will print this line of code if an error is encountered")
5else:
6 print("I will print this line of code if there's no error encountered")
7finally:
8 print("I will print this line of code even if there's an error or no error encountered")