ITE 260: Computer Programming 1
Module #11 Student Activity Sheets
Name: _________________________________________________________ Class
number:_____
Section: _________ Schedule: _________________________________ Date: ___________
Lesson title: Loops and Iteration - Part 2 Materials:
SAS
Lesson Objectives:
At the end of the session, your students should be able to:
1. Explain how for loop statement works in python
2. Describe the general syntax of for loop statement
3. Apply for loop structure and nested loop in the python References:
program https://www.freecodecamp.org/new
s/python-while-loop-tutorial/
Productivity Tip:
“However difficult life seems, there is always something you can do and succeed at.”- Stephen Hawking
1) Activity 2: Skill-building Activities
Let’s practice! After completing each exercise, you may refer to the Key to Corrections for
feedback. Try to complete each exercise before looking at the feedback.
A. Code Evaluation. Write the output of the Python Code.
1. What is the output of the following for loop statement?
CODE OUTPUT
for i in range(3):
print("Hello")
print("Goodbye")
2. What is the output of the following for loop statement?
CODE OUTPUT
row = 5
for i in range(1, row + 1, 1):
for j in range(1, i + 1):
print("*", end=' ')
print("")
3. What is the output of the following nested for loop statement?
CODE OUTPUT
This document is the property of PHINMA EDUCATION
ITE 260: Computer Programming 1
Module #11 Student Activity Sheets
Name: _________________________________________________________ Class
number:_____
Section: _________ Schedule: _________________________________ Date: ___________
for v in range (5):
for h in range(5):
print("*", end = " ")
print()
4. What is the output of the following for loop statement?
CODE OUTPUT
color = ['black', 'white', 'gray']
for index in range(len(color)):
print(color[index])
B. Coding Time: Open your code editors like Notepad++, Sublime, or any available IDE.
1. Create a program that will accept 5 numbers then count the number of odd and even
numbers
Expected Output:
WRITE YOUR CODE HERE
Enter 5 numbers:
1
2
5
4
1
ODD: 3
EVEN: 2
B. Activity 3: Check for Understanding
Write the answer to the following questions by completing the syntax.
QUESTION ANSWER
1. Use the range function to loop through for z in ________
a code set 10 times. print(z)
2. Loop through the items in the cats list. cats = ["Persian", "Siamese",
"Ragdoll"]
for z ___ cats:
print(z)
This document is the property of PHINMA EDUCATION
ITE 260: Computer Programming 1
Module #11 Student Activity Sheets
Name: _________________________________________________________ Class
number:_____
Section: _________ Schedule: _________________________________ Date: ___________
Answer the questions below about the following code:
n = 5
k = 5
for i in range(0,n+1):
for j in range(k-i,0,-1):
print("*",end=' ')
print()
3. What is the output of the presented
code?
4. What would happen if you changed
n+1 to n-1?
5. What would happen if you changed
print("*",end=' ') to
print(j,end=' ')?
This document is the property of PHINMA EDUCATION