diff --git a/15_Day/15_python_type_error.md b/15_Day/15_python_type_error.md index ccb4611..bc2afc5 100644 --- a/15_Day/15_python_type_error.md +++ b/15_Day/15_python_type_error.md @@ -35,9 +35,9 @@ ## Python Error Types -When we write code it common that we make a typo or other common errors. Based on the type of error we make python raise a kind of error which suggests us to fix it by reading the feedback. Understanding different types of errors in a certain programming language can help us to debug our code quick and in return it makes us a better programmer. +When we write code it's common that we make a typo or some other common error. If our code fails to run, the python interpreter will display a message, containing feedback with information on where the problem occurs and the type of an error. It will also sometimes gives us suggestions on a possible fix. Understanding different types of errors in programming languages will help us to debug our code quickly and also it makes us better at what we do. -Let's see the most common error types step by step by open our python interactive shell. Go to your you computer terminal and write, python, the python interactive shell will be opened. +Let's see the most common error types one by one. First let us open our python interactive shell. Go to your you computer terminal and write 'python'. The python interactive shell will be opened. ### SyntaxError @@ -56,7 +56,7 @@ SyntaxError: Missing parentheses in call to 'print'. Did you mean print('hello w >>> ``` -As you can see we made a syntax error because we forgot to enclose the string with parenthesis and python is already suggested us to fix. Let's fix it. +As you can see we made a syntax error because we forgot to enclose the string with parenthesis and python already suggests the solution. Let's fix it. ```py Last login: Tue Dec 3 15:20:41 on ttys002 @@ -74,7 +74,7 @@ hello world >>> ``` -The error was a _SyntaxError_ and we fixed and our code executed. Let see more error types. +The error was a _SyntaxError_. After the fix our code was executed without a hitch. Let see more error types. ### NameError @@ -93,7 +93,7 @@ NameError: name 'age' is not defined >>> ``` -As you can see from the above error, it says that name age is not defined. Yes, it is true. We did define an age variable but we were trying to print it as if we declare it. Now, lets fix this by declaring age variable and assigning with a value. +As you can see from the message above, name age is not defined. Yes, it is true. We did not define an age variable but we were trying to print it out as if we had had declared it. Now, lets fix this by declaring it and assigning with a value. ```py Last login: Tue Dec 3 15:20:41 on ttys002 @@ -131,7 +131,7 @@ IndexError: list index out of range >>> ``` -In the above example, python raised an _IndexError_ because the list has only 0 to 4 indexes, so it was out of range. +In the example above, python raised an _IndexError_, because the list has only indexes from 0 to 4 , so it was out of range. ### ModuleNotFoundError @@ -150,7 +150,7 @@ ModuleNotFoundError: No module named 'maths' >>> ``` -In the above example, I added extra s to math deliberately and _ModuleNotFoundError_ was raised. Lets fix the error by removing the extra added s from math. +In the example above, I added an extra s to math deliberately and _ModuleNotFoundError_ was raised. Lets fix it by removing the extra s from math. ```py Last login: Tue Dec 3 15:20:41 on ttys002 @@ -166,7 +166,7 @@ ModuleNotFoundError: No module named 'maths' >>> ``` -We fixed the error by removing the extra s. Now let's use some of the function from math module. +We fixed it, so let's use some of the functions from the math module. ### AttributeError @@ -190,7 +190,7 @@ AttributeError: module 'math' has no attribute 'PI' >>> ``` -As you can see, now again I made a mistake instead of pi, I tried to call a PI function from maths module that raise an attribute error, it means the function does not exist in the module. Lets fix it by change from PI to pi. +As you can see, I made a mistake again! Instead of pi, I tried to call a PI function from maths module. It raised an attribute error, it means, that the function does not exist in the module. Lets fix it by changing from PI to pi. ```py Last login: Tue Dec 3 15:20:41 on ttys002 @@ -234,7 +234,7 @@ KeyError: 'county' >>> ``` -As you can see, there was a typo in the key used to get the dictionary value. so, this is a key error and it is straight forward what to fix. Lets fix this. +As you can see, there was a typo in the key used to get the dictionary value. so, this is a key error and the fix is quite straight forward. Let's do this! ```py Last login: Tue Dec 3 15:20:41 on ttys002 @@ -254,7 +254,7 @@ KeyError: 'county' >>> ``` -We debug our error and our code ran and we got the value. +We debugged the error, our code ran and we got the value. ### TypeError @@ -273,7 +273,7 @@ TypeError: unsupported operand type(s) for +: 'int' and 'str' >>> ``` -In the above example, a TypeError is raised because we can not add number and string. First, we should convert the string to int or float. Let's fix this error. +In the example above, a TypeError is raised because we cannot add a number to a string. First solution would be to convert the string to int or float. Another solution would be converting the number to a string (the result then would be '43'). Let us follow the first fix. ```py Last login: Tue Dec 3 15:20:41 on ttys002 @@ -292,7 +292,7 @@ TypeError: unsupported operand type(s) for +: 'int' and 'str' >>> ``` -The remove the error and our and we got the result we expected. +Error removed and we got the result we expected. ### ImportError @@ -311,7 +311,7 @@ ImportError: cannot import name 'power' from 'math' >>> ``` -There is no function called power in the math module instead we have _pow_. Lets correct it +There is no function called power in the math module, it goes with a different name: _pow_. Let's correct it: ```py Last login: Tue Dec 3 15:20:41 on ttys002 @@ -344,7 +344,7 @@ ValueError: invalid literal for int() with base 10: '12a' >>> ``` -We can not change string to a number. +In this case we cannot change the given string to a number, because of the 'a' letter in it. ### ZeroDivisionError @@ -361,10 +361,10 @@ ZeroDivisionError: division by zero >>> ``` -We can not divide a number by zero. +We cannot divide a number by zero. We have covered some of the python error types, if you want to check more about it check the python documentation about python error types. -If you are good at reading the error types then you will be able to fix your bugs fast and you will be also a better programmer. +If you are good at reading the error types then you will be able to fix your bugs fast and you will also become a better programmer. ## 💻 Exercises: Day 15