0% found this document useful (0 votes)
3 views18 pages

Others Class PDF

The document covers the introduction to lists and loops in Python, explaining how to store and display data using lists, as well as the importance of indentation in coding. It outlines the two types of loops, 'for' and 'while', and provides coding examples and challenges for practical understanding. Additionally, it introduces the Turtle module for drawing shapes and includes quizzes to assess comprehension.

Uploaded by

arif01774001718
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views18 pages

Others Class PDF

The document covers the introduction to lists and loops in Python, explaining how to store and display data using lists, as well as the importance of indentation in coding. It outlines the two types of loops, 'for' and 'while', and provides coding examples and challenges for practical understanding. Additionally, it introduces the Turtle module for drawing shapes and includes quizzes to assess comprehension.

Uploaded by

arif01774001718
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Meeting 3

LIST

What will we learn today?


1. Introduction of List Concepts

21
Meeting 3 - Lists

INTRO TO LISTS
Lists

Do you remember what a variable is?


How much data can a variable store?
What should we do if we want to store more than 1 data?

List is a place to store a lot of data sequentially.

Imagine you are making a game and want to save the name of the player in
each team. If you code a variable for each player name, it will look as in the
image below. It uses a lot of space, right?

With coding, we can make it simpler if we use a list concept.

In lists, the data is sorted (indexed) from the numbers 0, 1, 2, 3,....


so to display the data in the first order we use [0], the second data uses
[1], and so on.
To display the data in the last order and to make it faster we can use [-1],
the 2nd last data [-2], and so on.

22
Meeting 3 - Lists

LIST IN PYTHON

?
? ? QUIZ TIME
Type the answer to the question below in chat!

In list, the data indexed from the number 1

FALSE TRUE

UFO_players=[‘Peter’, ‘Pablo’, ‘Polly’]


From the list above, index number 2 is...

Peter Pablo Polly

rockets_players=[‘Rory’, ‘Rav’, ‘Rachel’]


From the list above, index number 2 is...

FALSE TRUE

23
Meeting 3 - Lists

LIST IN PYTHON

We will learn how to display data in lists.

1. Click +Create repl


2. Choose Python template, add title lists, then +Create repl
3. Type the following code in a text editor to display a list of fruits,
then press the Run button

4. Type the following code in the text editor, then press the Run button

To display the amount of data


To display the data type

How much is the data? _______________


What is the data type? _______________

5. Type the following code in the text editor, then press the Run button

To display the first data


To display the second data
To display the last data

24
Meeting 3 - Lists

LIST IN PYTHON
W hat is the first data? _______________
What is the second data? __________________
What is the last data? ________________

In addition to storing data with the same data type, lists


can also accommodate data with different data types.
Let’s try to practice!

6. Type the following code in the text editor, then press the Run button

CHALLENGE
Try to display the data in the 2nd, 5th, and last order in the
Pokemon list below by coding Python in Replit!
pokemon = [Pikachu, Bulbasaur, Charmeleon, Squirtle,
Wartortle, Kakuna, Kadabra]

5th data= ..........


Last data= ..........

Coding
To store data in the list we use the following code:
list_name = [Data, Data, Data]
To display the number of data in the list we use the code:
print(len(list_name))
To display the data type we use the code:
print(t ype(list _name))
To display the order of data in the list we use the code:
print(list _name[index])

25
Meeting 3 - Lists

PYTHON AND TURTLE


Turtle

In addition to displaying text, we can


also create simple images in Python
Python provides a Turtle module that
moves the robotic “turtle” around the
screen, as well as draws with a pen as
it walks.

Turtle is a coding package that can be used to draw


lines, circles, and other more complex shapes in
Python.

The Turtle module allows us to draw by giving


instructions to the turtle
The instructions given may include when to start or
stop drawing, where to move, what colors to use, and
so on.
We will learn to draw a triangle using a turtle.
1. Click +Create repl
2. Choose the Python template, add title myturtle, then +Create repl
3. Type the following code in the text editor to draw a triangle
with an angle of 120 degrees each, then press the Run button

To call the turtle coding package

To draw with a pen

To make a turtle shape


To color the line in blue
To move forward draw a 50px long
straight line
26
DRAWING WITH TURTLE

To turn left at an angle of 120

CHALLENGE
Try to create a square shape with 100px long straight lines
and green lines using Python’s coding in Replit!

Let’s Play With TYNKER


We’re going to play Tynker using Python
concepts!
Link : https://www.tynker.com/
Material : Python 1 - Lesson 1
Level : 8 - 14

27
HOWHO WA WSA TSO TDOADYA’YS’

QUIZ TIME ?
? ?
Let’s check your understanding by answering the
question in the link below
Open Link :h ttps://forms.gle/hto79xqeY5VFpPok8

WHAT’S NEXT?

LOOPING

28
Meeting 4

LOOPS

What will we learn today?


1. Introduction of the Loops Concept in Python

29
Meeting 4 - Loops

INTRO TO INDENTATION
After successfully learning variables and data
types, it’s time for you to learn about Indentation
and Loops
Have you ever seen messy and
disorganized coding?
Of course, it will be difficult to
understand and difficult to fix the error,
right?
Python has a rule for typing code to make the code look
neat which is called Indentation
Do you know what Indentation is?

Indentat ion

Indentation is writing paragraphs that are


slightly indented to group blocks of program
code.

30
Meeting 4 - Loops

INTRO TO LOOPS
When is indentation used?
Indentation is very important used in several coding concepts such as
Loops (for & while), conditional (if, else, elif), and function.
Indentation is used to make it easier for humans to read program code and
is tasked with defining the structure of program code blocks

Making mistakes in indenting Python


code can cause program errors.
We will start using loops in coding so pay attention to your indents in
coding.
The indent is created by pressing the Tab key on the keyboard.
Have you ever coded with the same
command over and over?
Of course, it takes a lot of time and
effort, doesn’t it make the same code
over and over again?

Using repeat
can shorten the
coding that is
compiled

Loops

Loops are a method for running the same code


over and over again.

31
Meeting 4 - Loops

LOOPS
There are 2 types of loops in python, they are:
For Loops
For loops are used when you know how many times you
want to run the code loop.

While Loops
While loops are used when you don’t know how many
times you want to run the coding loop and the coding will
loop over and over as long as the condition is met.

What do you think is the difference


between the two types of loops?

Do you know what code to use to loop in Python?

?
? ? QUIZ TIME
Type the answer to the question below in chat!

Indentation is used when writing only loop


code

FALSE TRUE

Which loop to use, when we know how many


times we want to repeat the code?

While Do while
For Loop
Loop

32
Meeting 4 - Loops

FOR LOOPS
We will learn to display data using For Loops.
1. Open the link : https://replit.com
2. Log in with your Google account
3. Click +Create
4. Choose the Python template, add title for_loops,
5. then +Create repl
Type the following code in the text editor to display the text
5 times, then press the Run button

Loop variable The


amount
of loop

Repeated
coding

6. Type the following code in the text editor to display


he text + variable 5 times, then press the Run button

7. Type the following code in the text editor to display the


numbers 0-9, then press the Run button
Loop variable
10 times repetition of
numbers from 0 - 9
Loop variable

Starts at 0 by default, increases by 1 (by default), and ends at the specified


number.
to display the numbers 1-10, change the code print(x) to be like this:

8. Type the following code in the text editor to count down


the numbers 10 - 1 with the concept of decrement, then press
the Run button

33
Meeting 4 - Loops

FOR LOOPS

(-) Decrement : substraction


score x = x - 1

Start End
9. Type the following code in the text editor to calculate multiples
numbers with the concept of increment, then press the Run button

(+) Increment : addition


score x = x + 2
10. Type the following code in the text editor to display the data
in list pokemon in sequence, then press the Run button

11. Type the following code in the text editor to display the number
of data loops entered, then press the Run button

To convert a string variable to an integer so that the


loop can be processed

Coding
To create a coding loop in python we use the code:
for Counter_Variable in range (Number) :
or
for Counter_Variable in range (Start, End, Increment/decrement) :
or
for Counter_Variable in Variable :

34
Meeting 4 - Loops

WHILE LOOPS
We will learn to display data using While Loops.

1. Click +Create
2. Choose the Python template, add title while_loops, then +Create
3.
repl
Type the following code in the text editor to display the
numbers 0-9, then press the Run button

Star t

Condition end when i is less


than 10
Increment which has the
same meaning as i = i + 1

4. Type the following code in the text editor to count down


the numbers 5-1, then press the Run button

Condition end when b is


not equal to 0
Decrement which has the
same meaning as i = i - 1

Coding
To create a coding loop in python we use the code:
while Condition end :
or

while not Condition end :

35
Meeting 4 - Loops

WITH OR WITHOUT INDENTATION


How important is the influence of indentation in writing
coding?
Type the following code, then press the Run button!

What is the result from coding you made?


Also try to create and run the following code!

Is there a difference in the results of coding with and


without indentation?

What do you think is the difference


between both codings?

36
Meeting 4 - Loops

TURTLE
We will learn how to draw a square using a turtle.

1. Click +Create repl


2. Choose Python template, add title myturtle, then +Create repl
3. Type the following code in the text editor to draw a square
with a 90 degree angle using the for loop concept,
then press the Run button

We can adjust the speed of the turtle


when drawing from the slowest to the
fastest:
“slowest”, “slow”, “normal”, “fast”, and
“fastest”

CHALLENGE
Try to display a triangle image using the concept of a for loop
with a green line!

Additional Lesson Additional lessons can be done if there is still


time left to do it
Let’s Play With TYNKER
We’re going to play Tynker using Python
concepts!
Link : https://www.tynker.com/
Material : Python 1 - Lesson 2

37
HOWHO WA WSA TSO TDOADYA’YS’

QUIZ TIME ?
? ?
Let’s check your understanding by answering the
question in the link below
Open Link : https://forms.gle/ANyTt9maCkfAZAMq5

WHAT’S NEXT?

CONDITIONAL

38

You might also like