Introduction to Python

Form 4 - Computer

2023-2024

Floor 4 - Computer Room

Mr. Peter

Outline

Outline

While Loop

1

List Structure

2

Exercises

3

While Loop Statement

1.

2.

Tab

while Condition :

Command1

Same

1.

2.

While loop statement - Ex14_1

List all elements using len() function

Write a Python program that iterate each element in a provided List and print it.

elements = [ 1, 2, 3, 5, 10 ]

Code Provided

Expected outcome after your program executed

1

2

3

5

10

Print in the console

Save the file as "XX_YYYY_Ex14_1.py"

Same

1.

2.

While loop statement - Ex14_2

List reversed elements

Write a Python program that iterate each element in a provided List and print it.

elements = [ 1, 2, 3, 5, 10 ]

Code Provided

Expected outcome after your program executed

10

5

3

2

1

Print in the console

Save the file as "XX_YYYY_Ex14_2.py"

Same

1.

2.

While loop statement - Ex14_3

Save the file as "XX_YYYY_Ex14_3.py"

Product all values from the elements

Write a Python program that iterate each element in a provided List, and the calculate the product of each elements in the list.

elements = [ 1, 2, 3, 5, 10 ]

Code Provided

Expected outcome after your program executed

300

Print in the console

1 \times 2 \times 3 \times 5 \times 10 = 300

Same

1.

2.

While loop statement - Ex14_4

Show all odd number of the list

Write a Python program that iterate each element in a provided List and print it if the element is not an even number.

elements = [ 1, 2, 3, 5, 10 ]

Code Provided

Expected outcome after your program executed

1

3

5

Print in the console

Save the file as "XX_YYYY_Ex14_4.py"

Python - List

By Mr Peter

Python - List

  • 151