Introduction to Python

Form 4 - 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

Same

Differrent

1.

2.

While loop statement - Ex12_1

Save the file as "XX_YYYY_Ex12_1.py"

Mr Peter's Apple Vision Pro

If Mr Peter plans to purchase an Apple Vision Pro priced at $3499, he intends to save money by setting aside $1 per day. Moreover, he aims to increase his daily savings by $2, that means saving two dollars more than the previous day. How many days will it take for Peter to accumulate enough money to buy the Apple Vision Pro?

1.

Apple Vision Pro: $3499

2.

Save money start from $1 in the first day

3.

4.

Saving two dollars more than the previous day

How many days

Same

Differrent

1.

2.

While loop statement - Ex12_2

Stairs

There is a long staircase. If you climb it by taking 2 steps at a time, there will be 1 step remaining at the end. If you climb it by taking 3 steps at a time, there will be 2 steps remaining. If you climb it by taking 5 steps at a time, there will be 4 steps remaining. If you climb it by taking 6 steps at a time, there will be 5 steps remaining. Only by taking 7 steps at a time will there be exactly 1 step remaining. How many steps does this staircase have in total?

1.

Taking 2 steps => 1 step remaining

2.

Taking 3 steps => 2 steps remaining

3.

Taking 5 steps => 4 steps remaining

4.

Taking 6 steps => 5 steps remaining

5.

Taking 7 steps => 1 step remaining

Save the file as "XX_YYYY_Ex12_2.py"

Only 1 ~ 1000 stairs are considered, the answer is 29,239,449,659,869.

Same

Differrent

1.

2.

While loop statement - Bonus Question

Write a python program to get the height of the table

Save the file as "XX_YYYY_Bonus.py"

Python - While Loop

By Mr Peter

Python - While Loop

  • 245