|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "1. SyntaxError: This exception is raised when the interpreter encounters a syntax error in the code, such as a misspelled keyword, a missing colon, or an unbalanced parenthesis.\n", |
| 8 | + "\n", |
| 9 | + "2. TypeError: This exception is raised when an operation or function is applied to an object of the wrong type, such as adding a string to an integer.\n", |
| 10 | + "\n", |
| 11 | + "3. NameError: This exception is raised when a variable or function name is not found in the current scope.\n", |
| 12 | + "\n", |
| 13 | + "4. IndexError: This exception is raised when an index is out of range for a list, tuple, or other sequence types.\n", |
| 14 | + "\n", |
| 15 | + "5. KeyError: This exception is raised when a key is not found in a dictionary.\n", |
| 16 | + "\n", |
| 17 | + "6. ValueError: This exception is raised when a function or method is called with an invalid argument or input, such as trying to convert a string to an integer when the string does not represent a valid integer.\n", |
| 18 | + "\n", |
| 19 | + "7. AttributeError: This exception is raised when an attribute or method is not found on an object, such as trying to access a non-existent attribute of a class instance.\n", |
| 20 | + "\n", |
| 21 | + "8. IOError: This exception is raised when an I/O operation, such as reading or writing a file, fails due to an input/output error.\n", |
| 22 | + "\n", |
| 23 | + "9. ZeroDivisionError: This exception is raised when an attempt is made to divide a number by zero.\n", |
| 24 | + "\n", |
| 25 | + "10. ImportError: This exception is raised when an import statement fails to find or load a module." |
| 26 | + ] |
| 27 | + }, |
| 28 | + { |
| 29 | + "cell_type": "markdown", |
| 30 | + "metadata": {}, |
| 31 | + "source": [ |
| 32 | + "Difference between Syntax Error and Exceptions:\n", |
| 33 | + "\n", |
| 34 | + "Syntax Error: As the name suggests this error is caused by the wrong syntax in the code. It leads to the termination of the program.\n", |
| 35 | + "\n", |
| 36 | + "Exceptions: Exceptions are raised when the program is syntactically correct, but the code results in an error. This error does not stop the execution of the program, however, it changes the normal flow of the program." |
| 37 | + ] |
| 38 | + }, |
| 39 | + { |
| 40 | + "cell_type": "code", |
| 41 | + "execution_count": 1, |
| 42 | + "metadata": {}, |
| 43 | + "outputs": [ |
| 44 | + { |
| 45 | + "ename": "SyntaxError", |
| 46 | + "evalue": "expected ':' (3269522495.py, line 2)", |
| 47 | + "output_type": "error", |
| 48 | + "traceback": [ |
| 49 | + "\u001b[1;36m Cell \u001b[1;32mIn[1], line 2\u001b[1;36m\u001b[0m\n\u001b[1;33m if(amount > 2999)\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m expected ':'\n" |
| 50 | + ] |
| 51 | + } |
| 52 | + ], |
| 53 | + "source": [ |
| 54 | + "amount = 10000\n", |
| 55 | + "if(amount > 2999)\n", |
| 56 | + "print(\"You are eligible to purchase Dsa Self Paced\")\n" |
| 57 | + ] |
| 58 | + }, |
| 59 | + { |
| 60 | + "cell_type": "code", |
| 61 | + "execution_count": 2, |
| 62 | + "metadata": {}, |
| 63 | + "outputs": [ |
| 64 | + { |
| 65 | + "ename": "ZeroDivisionError", |
| 66 | + "evalue": "division by zero", |
| 67 | + "output_type": "error", |
| 68 | + "traceback": [ |
| 69 | + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", |
| 70 | + "\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", |
| 71 | + "Cell \u001b[1;32mIn[2], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m marks \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m10000\u001b[39m\n\u001b[1;32m----> 2\u001b[0m a \u001b[38;5;241m=\u001b[39m \u001b[43mmarks\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(a)\n", |
| 72 | + "\u001b[1;31mZeroDivisionError\u001b[0m: division by zero" |
| 73 | + ] |
| 74 | + } |
| 75 | + ], |
| 76 | + "source": [ |
| 77 | + "marks = 10000\n", |
| 78 | + "a = marks / 0\n", |
| 79 | + "print(a)\n" |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + "cell_type": "code", |
| 84 | + "execution_count": 3, |
| 85 | + "metadata": {}, |
| 86 | + "outputs": [ |
| 87 | + { |
| 88 | + "ename": "TypeError", |
| 89 | + "evalue": "unsupported operand type(s) for +: 'int' and 'str'", |
| 90 | + "output_type": "error", |
| 91 | + "traceback": [ |
| 92 | + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", |
| 93 | + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", |
| 94 | + "Cell \u001b[1;32mIn[3], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m x \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m5\u001b[39m\n\u001b[0;32m 2\u001b[0m y \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhello\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m----> 3\u001b[0m z \u001b[38;5;241m=\u001b[39m \u001b[43mx\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43my\u001b[49m \n", |
| 95 | + "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'int' and 'str'" |
| 96 | + ] |
| 97 | + } |
| 98 | + ], |
| 99 | + "source": [ |
| 100 | + "x = 5\n", |
| 101 | + "y = \"hello\"\n", |
| 102 | + "z = x + y " |
| 103 | + ] |
| 104 | + }, |
| 105 | + { |
| 106 | + "cell_type": "code", |
| 107 | + "execution_count": null, |
| 108 | + "metadata": {}, |
| 109 | + "outputs": [], |
| 110 | + "source": [] |
| 111 | + } |
| 112 | + ], |
| 113 | + "metadata": { |
| 114 | + "kernelspec": { |
| 115 | + "display_name": "Python 3", |
| 116 | + "language": "python", |
| 117 | + "name": "python3" |
| 118 | + }, |
| 119 | + "language_info": { |
| 120 | + "codemirror_mode": { |
| 121 | + "name": "ipython", |
| 122 | + "version": 3 |
| 123 | + }, |
| 124 | + "file_extension": ".py", |
| 125 | + "mimetype": "text/x-python", |
| 126 | + "name": "python", |
| 127 | + "nbconvert_exporter": "python", |
| 128 | + "pygments_lexer": "ipython3", |
| 129 | + "version": "3.12.5" |
| 130 | + } |
| 131 | + }, |
| 132 | + "nbformat": 4, |
| 133 | + "nbformat_minor": 2 |
| 134 | +} |
0 commit comments