0% found this document useful (0 votes)
24 views2 pages

Python_Loop_Worksheet_Class8.docx

Uploaded by

mittalpalash12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Python_Loop_Worksheet_Class8.docx

Uploaded by

mittalpalash12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

. .

Subject: COMPUTER
Python Worksheet: Loop Execution and Output
Name: ________ Date: _________
Class & Sec.: ______ Time : 30 Min.

Instructions:
1. Carefully read the given code snippets.
2. Write the output of each program.
3. Calculate the number of times the loop executes where applicable.

Part A: `for` Loop


1. for i in range(1, 6):
print(i)
2. for i in range(2, 10, 3):
print(i)
3. for i in range(1, 8):
if i == 4:
break
Part B: `while` Loop
4. x = 1
while x <= 5:
print(x)
x += 1
5. i = 1
while i < 6:
if i == 3:
i += 1
continue
print(i)
i += 1
Part C: `for-else` Loop
6. for i in range(1, 5):
print(i)
else:
print("Loop completed!")
7. for i in range(1, 5):
if i == 3:
break
print(i)
else:
print("Loop completed!")
Part D: Mixed Logic
8. count = 0
for i in range(3):
for j in range(2):
print(i, j)
count += 1
print("Total iterations:", count)
9. for i in range(3):
x=0
while x < 2:
print(i, x)
x += 1
Bonus Challenge
10.
for i in range(5):
if i % 2 == 0:
continue
print(i)

You might also like