Exception Handling: =================== two types of errors: 1) Syntax Errors 2) Runtime Errors 1) Syntax Error: ================ The error which occurs because of invalid syntax. # Syntax Errors # program to find the number is even or odd num = 27 if num % 2 == 0 print("It is an Even number.") else: print("It is an Odd number.") Note: ===== Syntax Errors ==> Human Mistakes/Developer mistakes ==> responsible by human Run Time Error: =============== ==> Also called as an Exceptions. ==> Runtime errors, we can observer during the execution of the program ==> Because of: 1) User input 2) Program logic 3) memory issue etc. a = int(input("Enter a value:")) b = 0 print(type(a)) print(a/b) What is an Exception? ===================== An unwanted and unexpected even that disturbs the normal flow of the program execution is called as an "Exception". ==> For exception, there is a class. Ex: Value Error, Zero Division Error, Type Error, Index Error etc. Exception Handling: =================== Exception will stop the program or will disturb the normal flow of execution of the program ==> to make execute the program normally by handling an exception ==> Exception handling is used. try-except block ==> to handle the exceptions Syntax: try: program that we want to execute normally even with exception except: exception # Exception Handling a = int(input("Enter a value:")) b = int(input("Enter a value:")) try: res = a / b except ZeroDivisionError: res = 0 print("Dividing the number with 0 is not possible.") print(res) =============================== Try with Multiple Exceptions: =============================== # evens = [2,4,6,8] # with total four index ==> 0 to 3 # # print(evens[4]) try: evens = [2,4,6,8] print(evens[4]) except ZeroDivisionError: print("Dividing a number with 0 is not possible.") except IndexError: print("Index out of range is used.") except TypeError: print("Index is not supported to use.") =============================== try-except-else block: ======================= When we might want to execute/run a certain block of code if the code block inside the try runs without any errors. In this, we can use "else". try: num = int(input("Enter a value:")) assert num % 2 == 0 except: print("Not an Even number.") else: rec = 1/num print(rec) ================================ Semester Results: ================= JNTU ==> person ==> 4/6 sub-1:60 sub-2: 40 sub-3: 50 sub-4: 70 sub-5: A sub-6: A ======================== Phonepe: ======= sending amount ==> friend 5000 Failure ==> Server Issue Technical issue at bank bank server running server