9. Exercise
• An item inside a list can be another list
• How can you access the item mouse?
10. Exercise
• An item inside a list can be another list
• How can you access and print the item mouse
• How can you access and print the item [‘a’] ?
11. Exercise
• An item inside a list can be another list
• How can you access and print the item mouse
• How can you access and print the item [‘a’] ?
• How can you access and print a?
12. Exercise
• An item inside a list can be another list
• How can you access and print the item mouse
• How can you access and print the item [‘a’] ?
• How can you access and print a?
13. Add two lists
• Just like strings, you can add lists
• This can be done in several ways
• Create a 3rd list that is a combination of the first two lists
14. Add two lists
• Just like strings, you can add lists
• This can be done in several ways
• Create a 3rd list that is a combination of the first two lists
15. Add two lists
• Just like strings, you can add lists
• This can be done in several ways
• Create a 3rd list that is a combination of the first two lists
• Append or extend to an existing list
What’s the difference between the two?
Try them and print your responses
16. Flowchart with lists and loops
• Given a list list_sample = [4, 3, 2, 5, 8], print all the even numbers
17. Flowchart with lists and loops
Start
Declare list_sample [4, 3, 2, 5, 8]
Declare a variable len_list that stored the length of the list
18. Flowchart with lists and loops
Start
Declare list_sample [4, 3, 2, 5, 8]
Declare a variable len_list that stored the length of the list
19. Flowchart with lists and loops
Start
Declare list_sample [4, 3, 2, 5, 8]
Declare a number a=0
Declare a variable len_list that stores the length of the list
If a <
len_list
Stop a = a+1
value =
list_sample[a]
If value is
a even
number
Print value
TrueFalse
False True
20. Flowchart with lists and loops
• Given a list list_sample = [4, 3, 2, 5, 8], print all the even numbers
21. Flowchart with lists and loops
• Given a list list_sample = [4, 3, 2, 5, 8], print all the even numbers
22. Flowchart with lists and loops
• Given a list list_sample = [4, 3, 2, 5, 8], print all the even numbers
Declare a number a=0
If a >
len_list
Stop a = a+1
value =
list_sample[a]
If value is
a even
number
Print value
True False
False True
23. Exercise: Design a chat bot - flowchart
• list_happy_words = [“joyful”, “happy”, “amazing”, “beautiful”]
• list_sad_words = [“sad”, “tears”, “crying”, “depressed”]
• list_games = [“tetris”, “flappy bird”, “snake”]
• Ask the user to enter a word that describes their feeling
• If the feeling they enter is one of the list_happy_words, print “Glad you are
happy” and exit.
• If the feeling they enter is one of the list_sad_words, ask the user to play
one of the games from the list list_games.
• Ask the user again how they are feeling and continue till the list of games is
exhausted.
• If you already suggested all the games and the user is still unhappy, exit.
24. Exercise: Design a chat bot - code
Start
Declare the 3 lists
Ask the user to input a word describing their feeling, save the string
Check if
word is a
part of
happy list
Check if
word is a
part of
sad list
True
Stop
Print
sentence
False
False True
Print
sentence
Print
game
25. Exercise: Design a chat bot - code
Start
Declare the 3 lists
Ask the user to input a word describing their feeling, save the string
Check if
word is a
part of
happy list
Check if
word is a
part of
sad list
True
Stop
Print
sentence
False
False True
Print
sentence
Print
game
Check if
your
games
list is
over
False