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

Write a Python program that prints a hollow reversed right-angled triangle pattern of stars with a fixed size of 10 lines.

Question

While loop statement - Ex01

Example

Save the file as "XX_YYYY_Ex01.py"

StringRepeat = Asterisk + ( ( n - 2 ) \times Space ) + Asterisk
**********
*       *
*      *
*     *
*    *
*   *
*  *
* *
**
*
Asterisks Repeat = Asterisk \times n
Asterisks Repeat = Asterisk \times 1

Write a Python program to print a nine-line pattern. The first part (lines one to five) has increasing lines with asterisks, each starting and ending with an asterisk and including increasing spaces. The second part (lines six to nine) mirrors the first part, excluding the middle line. Use loops and nested loops to manage the spaces and asterisks.

Question

While loop statement - Ex02

Example

Save the file as "XX_YYYY_Ex02.py"

*
**
* *
*  *
*   *
*  *
* *
**
*

Write a Python program that prints a hollow isosceles triangle pattern of stars with a fixed size of 10 lines.

Question

While loop statement - Ex03

Example

Save the file as "XX_YYYY_Ex03.py"

         *
        * *
       *   *
      *     *
     *       *
    *         *
   *           *
  *             *
 *               *
*******************

Python - While Loop 06

By Mr Peter

Python - While Loop 06

  • 220