mirror of
https://github.com/Asabeneh/30-Days-Of-Python.git
synced 2026-06-06 21:09:15 +08:00
day 1 bug fixes
This commit is contained in:
parent
b0806c6bad
commit
42185ef5f1
Binary file not shown.
|
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 126 KiB |
57
readme.md
57
readme.md
@ -49,7 +49,7 @@ If you are a macOS user. Click the button encircled in red.
|
||||
|
||||
[](https://www.python.org/)
|
||||
|
||||
To check if python is installed write the following command on your device terminal
|
||||
To check if python is installed write the following command on your device terminal.
|
||||
```shell
|
||||
python --version
|
||||
```
|
||||
@ -73,27 +73,27 @@ Lets write our very first script on the python scripting shell.
|
||||

|
||||
|
||||
Well done, you wrote your first python script on python interactive shell. How do we close this shell ?
|
||||
To close the shell, next to this symbol >> write **exit()** command and press Enter
|
||||
To close the shell, next to this symbol >> write **exit()** command and press Enter.
|
||||
|
||||

|
||||
Now, you knew how to open the python interactive shell and how to exit from it.
|
||||
|
||||
Python can give you result if you write scripts what python understands if not it returns errors. Let's make a deliberate mistake and see what python will return
|
||||
Python can give you result if you write scripts what python understands if not it returns errors. Let's make a deliberate mistake and see what python will return.
|
||||
|
||||

|
||||
|
||||
As you can see from the returned error, python is so clever that it knows the mistake we made and which was *Syntax Error: invalid syntax*. Using x as multiplication in python is a syntax error because (x) is not a valid syntax in python. Instead of (**x**) we use asterisk (*) for multiplication. The returned error clearly shows what to fix.
|
||||
The process of identifying and removing errors from a program is called *debugging*. Lets debug it by replaced * in place of **x**.
|
||||
The process of identifying and removing errors from a program is called *debugging*. Let's debug it by replacing * in place of **x**.
|
||||
|
||||

|
||||
|
||||
Our bug was fixed and the code run and we got a result we were expecting. As a programmer you will see such kind of errors on daily basis. It is good to know how to debug. To be good at debugging you should understand what kind of errors you are facing:SyntaxError, IndexError, ModuleNotFoundError, KeyError, ImportError etc. We will see more about different python ***error types*** in later section .
|
||||
|
||||
Let's practice more , how to use python interactive shell. Go to your terminal or command prompt and write the word **python**
|
||||
Let's practice more , how to use python interactive shell. Go to your terminal or command prompt and write the word **python**.
|
||||
|
||||

|
||||
|
||||
The python interactive shell is open and lets do some basic maths(addition, subtraction, multiplication, division, modulus, exponential).
|
||||
The python interactive shell is open and lets do some basic mathematics operations(addition, subtraction, multiplication, division, modulus, exponential).
|
||||
Lets do some maths first before we write any python code:
|
||||
- 2 + 3 = 5
|
||||
- 3 - 2 = 1
|
||||
@ -119,12 +119,12 @@ Before we move on to the next section, lets practice more on the python interact
|
||||

|
||||
|
||||
### Installing Visual Studio Code
|
||||
The python interactive shell is good to try and test small script codes but it won't be for a big project. In real work environment, developers use different coding editors to write code. In this 30 days python programming challenge we will use visual studio code. Visual studio code is a very popular open source text editor. I am a fn of vscode and I would recommend to [download](https://code.visualstudio.com/) visual studio code, but if you are in favor of other editors, feel free to follow with what you have.
|
||||
The python interactive shell is good to try and test small script codes but it won't be for a big project. In real work environment, developers use different code editors to write codes. In this 30 days python programming challenge we will use visual studio code. Visual studio code is a very popular open source text editor. I am a fun of vscode and I would recommend to [download](https://code.visualstudio.com/) visual studio code, but if you are in favor of other editors, feel free to follow with what you have.
|
||||
|
||||
[](https://code.visualstudio.com/)
|
||||
If you installed visual studio code, lets see how to use it.
|
||||
If you installed visual studio code, let's see how to use it.
|
||||
#### How to visual studio code
|
||||
Open the visual studio code by double click the visual studio icon. When you open it you will get this kind of interface. Try to interact with the labelled icons.
|
||||
Open the visual studio code by double clicking the visual studio icon. When you open it you will get this kind of interface. Try to interact with the labelled icons.
|
||||

|
||||
|
||||
Create a folder name 30DaysOfPython on your desktop. Then open it using visual studio code.
|
||||
@ -132,10 +132,10 @@ Create a folder name 30DaysOfPython on your desktop. Then open it using visual s
|
||||

|
||||

|
||||
|
||||
After you opened you can create file and folder inside the your project directory which is 30DaysOfPython. As you can see bellow, I have created the very first file, helloworld.py. You can do the same.
|
||||
After you opened you can create file and folder inside the your project directory which is 30DaysOfPython. As you can see below, I have created the very first file, helloworld.py. You can do the same.
|
||||

|
||||
|
||||
After a long day of coding, this is it, you will close the project.
|
||||
After a long day of coding, you want to close your code editor, right ?. This is how you will close the opened project.
|
||||

|
||||
Congratulations, you have finished setting up the development environment. Let's start coding.
|
||||
|
||||
@ -143,7 +143,8 @@ Congratulations, you have finished setting up the development environment. Let's
|
||||
### Comment
|
||||
Comment is very important to make code more readable and to leave to remark in our code. Python doesn't run comment part of our code.
|
||||
Any text starts with hash(#) in python is a comment.
|
||||
Example
|
||||
|
||||
**Example:**
|
||||
```shell
|
||||
# This is the first comment
|
||||
# This is the second comment
|
||||
@ -163,7 +164,8 @@ In python there are several types of data types. We will get started with the mo
|
||||
1 + j, 2 + 4j
|
||||
#### String
|
||||
A collection of one or more characters under in single or double quote. If a string is more than one sentence we use triple quote.
|
||||
Example:
|
||||
|
||||
**Example:**
|
||||
```py
|
||||
'Asabeneh'
|
||||
'Finland'
|
||||
@ -174,15 +176,15 @@ In python there are several types of data types. We will get started with the mo
|
||||
#### Booleans
|
||||
A boolean data type is either True or False value.
|
||||
|
||||
Example:
|
||||
**Example:**
|
||||
```python
|
||||
True # if the light on, if it is on the value is True
|
||||
False # if the light off, if it is off the value is False
|
||||
```
|
||||
#### List
|
||||
Python list is an ordered collection which allows to store of different data type items. A list is similar to an array in JavaScript
|
||||
Python list is an ordered collection which allows to store of different data type items. A list is similar to an array in JavaScript.
|
||||
|
||||
Example:
|
||||
**Example:**
|
||||
```py
|
||||
['Banana', 'Orange', 'Mango', 'Avocado'] # all the same data type in the list
|
||||
['Banana', 10, False, 9.81] # different data types in the list
|
||||
@ -191,35 +193,38 @@ Python list is an ordered collection which allows to store of different data typ
|
||||
#### Dictionary
|
||||
A python dictionary object is an unordered collection of data in a key:value pair.
|
||||
|
||||
Example:
|
||||
**Example:**
|
||||
```py
|
||||
{"name":"Asabeneh", "country":"Finland", age:250, "is_married":True}
|
||||
```
|
||||
#### Tuple
|
||||
A tuple is an ordered collection of different data types like list but tuples can not be modified once they are created. They are immutable.
|
||||
|
||||
Example
|
||||
**Example**
|
||||
```py
|
||||
('Asabeneh', 'Brook', 'Abraham', 'Lidiya')
|
||||
```
|
||||
#### Set
|
||||
A set is a collection data types similar to list and tuple. Unlike list and tuple, set is not an ordered collection of items. Like in mathematics, set in python store only unique elements.
|
||||
|
||||
Example
|
||||
In later sections, we will go in detail in each and every python data types.
|
||||
|
||||
**Example:**
|
||||
```py
|
||||
{3.14, 9.81, 2.7} # order is not important in set
|
||||
```
|
||||
### Checking Data types
|
||||
To check the data type of a certain data type we use the **type**
|
||||
To check the data type of a certain data type we use the **type** function. In the following terminal you will see the different python data types:
|
||||
|
||||

|
||||
### Python File
|
||||
First open your project folder, 30DaysOfPython. If you don't have this folder,create a folder name called 30DaysOfPython. Inside this folder, create a file called helloworld.py. Now, let's do what we did on python interactive shell using visual studio code.
|
||||
The python interactive shell was printing without using **print** but on visual studio code to see our result we should use a built in function **print(some data to print)**.
|
||||
|
||||

|
||||
|
||||
**Example:**
|
||||
helloworld.py
|
||||
```py
|
||||
# Day 1 - 30DaysOfPython Challenge
|
||||
# Day 1 - 30DaysOfPython Challenge
|
||||
print(2 + 3) # addition(+)
|
||||
print(3 - 1) # subtraction(-)
|
||||
print(2 * 3) # multiplication(*)
|
||||
@ -241,7 +246,7 @@ helloworld.py
|
||||
|
||||
## Exercises - Day 1
|
||||
1. Check the python version you are using
|
||||
1. Open the python interactive shell and do the following operations. The operands are 3 and 4. Check the example above
|
||||
2. Open the python interactive shell and do the following operations. The operands are 3 and 4. Check the example above
|
||||
- addition(+)
|
||||
- subtraction(-)
|
||||
- multiplication(*)
|
||||
@ -254,7 +259,7 @@ helloworld.py
|
||||
- Your family name
|
||||
- Your country
|
||||
- I am enjoying 30 days of python
|
||||
1. Check the data types of the following data:
|
||||
2. Check the data types of the following data:
|
||||
- 10
|
||||
- 9.8
|
||||
- 3.14
|
||||
@ -263,7 +268,7 @@ helloworld.py
|
||||
- Your name
|
||||
- Your family name
|
||||
- Your country
|
||||
2. Create a folder name day_1 inside 30DaysOfPython folder. Inside day_1 folder, create a file python file helloword.py and repeat question 1, 2, 3 and 4. Remember to use *print()* when you are working on a python file. Then run the file.
|
||||
3. Create a folder name day_1 inside 30DaysOfPython folder. Inside day_1 folder, create a file python file helloword.py and repeat question 1, 2, 3 and 4. Remember to use *print()* when you are working on a python file. Then run the file.
|
||||
|
||||
# Day 2
|
||||
## Variables
|
||||
|
||||
Loading…
Reference in New Issue
Block a user