Introduction to Python
Form 4 - Computer
2023-2024
Floor 4 - Computer Room
Mr. Peter
Outline
Outline
While Loop
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2214875/images/9811262/pasted-from-clipboard.png)
1
Number Sequences
2
Exercises
3
While Loop Statement
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1490014/images/9343467/pasted-from-clipboard.png)
1.
2.
Tab
while Condition :
Command1
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2214875/images/10437733/pasted-from-clipboard.png)
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 100 to 1.
Question
While loop statement - Ex09_1
100
99
98
97
96
...
1
Example
Save the file as "XX_YYYY_Ex09_1.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_2
1 + 2 + 3 + 4 + 5 + 6 + ...... + 95 + 96 + 97 + 98 + 99 + 100
= ?
Example
Save the file as "XX_YYYY_Ex09_2.py"
Python - While Loop
By Mr Peter
Python - While Loop
- 301