You are on page 1of 19

LAB MODULE

Coding & Big Data

Week 6
Nested iteration in Python
Nested Loop

Nested While Loop


Outline
Practice I

Nested For Loop

Practice II

Practice III

Submission

References
Nested Loop
What is Nested Basically, a loop inside a loop.

Loop?
Loop can be nested in python. When a
loop is nested inside another loop, the
inner loop runs many times inside the
outer loop. In each iteration of the outer
loop, the inner loop will be re-started.
Nested While Loop
Nested While
Loop

A while Loop inside a while loop.


Example

Output

Source Code
Practice I:
For student who have the last digit of student ID is odd, create a code to generate output as picture 1.

For student who have the last digit of student ID is even, create a code to generate output as picture 2.

Picture 1 Picture 2
Nested For Loop
Nested For Loop

A for Loop inside a for loop.


Example

Output
Source Code
Practice II:
For student who have the last digit of student ID is odd, create a code to generate output as picture 1.

For student who have the last digit of student ID is even, create a code to generate output as picture 2.

Picture 1 Picture 2
Practice III: a bit challenge
Create a code to allow user input the number of the line, and will count up started from 11. The
number will form a triangle pattern as below.
Submission
Screenshot & Upload to eCampus
Please take a screenshot of source code and terminal of practice 1, practice 2 and practice 3. Compile it
into word or pdf file. Then, submit it to e-Campus.
References
Python Loops - For, While, Nested Loops With Examples (softwaretestinghelp.com)

You might also like