Introduction to Python

Form 3 - Computer

2023-2024

Floor 4 - Computer Room

Mr. Peter

Outline

Outline

While Loop

1

Number Sequences

2

Exercises

3

While Loop Statement

1.

2.

Tab

while Condition :

Command1

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

i

_______

_______

_______

_______

_______

_______

i < 5

_______

_______

_______

_______

_______

_______

0

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

i

_______

_______

_______

_______

_______

_______

i < 5

_______

_______

_______

_______

_______

_______

0

True

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

i

_______

_______

_______

_______

_______

_______

i < 5

_______

_______

_______

_______

_______

_______

0

True

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

i

_______

_______

_______

_______

_______

_______

i < 5

_______

_______

_______

_______

_______

_______

0

True

1

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

i

_______

_______

_______

_______

_______

_______

i < 5

_______

_______

_______

_______

_______

_______

0

True

1

True

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

i

_______

_______

_______

_______

_______

_______

i < 5

_______

_______

_______

_______

_______

_______

0

True

1

True

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

i

_______

_______

_______

_______

_______

_______

i < 5

_______

_______

_______

_______

_______

_______

0

True

1

True

2

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

i

_______

_______

_______

_______

_______

_______

i < 5

_______

_______

_______

_______

_______

_______

0

True

1

True

2

True

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

i

_______

_______

_______

_______

_______

_______

i < 5

_______

_______

_______

_______

_______

_______

0

True

1

True

2

True

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

i

_______

_______

_______

_______

_______

_______

i < 5

_______

_______

_______

_______

_______

_______

0

True

1

True

2

True

3

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

i

_______

_______

_______

_______

_______

_______

i < 5

_______

_______

_______

_______

_______

_______

0

True

1

True

2

True

3

True

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

i

_______

_______

_______

_______

_______

_______

i < 5

_______

_______

_______

_______

_______

_______

0

True

1

True

2

True

3

True

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

i

_______

_______

_______

_______

_______

_______

i < 5

_______

_______

_______

_______

_______

_______

0

True

1

True

2

True

3

True

4

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

i

_______

_______

_______

_______

_______

_______

i < 5

_______

_______

_______

_______

_______

_______

0

True

1

True

2

True

3

True

4

True

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

i

_______

_______

_______

_______

_______

_______

i < 5

_______

_______

_______

_______

_______

_______

0

True

1

True

2

True

3

True

4

True

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

i

_______

_______

_______

_______

_______

_______

i < 5

_______

_______

_______

_______

_______

_______

0

True

1

True

2

True

3

True

4

True

5

While Loop Statement

1.

2.

while i < 5 :

3.

Tab

4.

Tab

i = 0

print(i)

i = i + 1

i

_______

_______

_______

_______

_______

_______

i < 5

_______

_______

_______

_______

_______

_______

0

True

1

True

2

True

3

True

4

True

5

False

Same

Differrent

1.

2.

Write a Python code to create a loop printing number from 1 to 100, each loop increases 2.

Question

While loop statement - Ex09_1

1

3

5

7

...

97

99

Example

Save the file as "XX_YYYY_Ex09_1.py"

Same

Differrent

1.

2.

Write a Python code to create a loop printing number from 100 to 1.

Question

While loop statement - Ex09_2

100

99

98

97

96

...

1

Example

Save the file as "XX_YYYY_Ex09_2.py"

Same

Differrent

1.

2.

Write a Python with While Loop statement to sum a sequence of number from 1 to 100

Question

While loop statement - Ex09_3

1 + 2 + 3 + 4 + 5 + 6 + ...... + 95 + 96 + 97 + 98 + 99 + 100

= ?

Example

Save the file as "XX_YYYY_Ex09_3.py"

Python - While Loop

By Mr Peter

Python - While Loop

  • 169