
LOOPS
Presentation
•
Computers
•
10th Grade
•
Medium
Tempa Rinchen
Used 11+ times
FREE Resource
10 Slides • 12 Questions
1
By Tempa Rinchen
2
Python has two types of loops:
while loop
for loop
Both loops help in repeating a block of code
3
i = 1
while i < 6:
print(i)
i += 1
-Repeats as long as the condition is true
- Don’t forget to increment or modify the loop variable, or it becomes an infinite loop
4
i = 1
while i < 6:
print(i)
if i == 3:
break
i += 1
- break exits the loop even if the condition is still true
5
i = 0
while i < 6:
i += 1
if i == 3:
continue
print(i)
Skips the current iteration when i == 3, then continues
6
for x in range(6):
print(x)
- A for loop is used for iterating over a sequence (list,tuple,strings)
- Generates a sequence: 0 to 5 (not including 6)
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
7
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
if x == "banana":
break
Exit the loop when x is "banana"
8
fruits = ["apple", "banana", "cherry"]
for x in fruits:
if x == "banana":
continue
print(x)
Exit the loop when x is "banana"
9
from turtle import*
fd(100)
rt(90)
fd(100)
rt(90)
fd(100)
rt(90)
fd(100)
from turtle import*
for i in range(4):
fd(100)
rt(90)
10
Sonam wants to generate multiplication table of 1, 2 and 3 upto 10 using nested while loop. Write the code
11
Multiple Choice
What is the purpose of a while loop in Python?
To iterate over a sequence of items
To define a function
To execute a set of statements as long as a condition is true
To create a list
12
Multiple Choice
What will happen if you forget to increment the variable in a while loop?
The loop will continue forever
The loop will execute twice
The loop will execute only once
The program will crash
13
Multiple Choice
What does the break statement do in a loop?
It pauses the loop
It skips the current iteration
It stops the loop immediately
It restarts the loop
14
Multiple Choice
What will the following code print? fruits = ['apple', 'banana', 'cherry']; for x in fruits: print(x)
apple banana cherry
banana cherry apple
cherry banana apple
apple, banana, cherry
15
Multiple Choice
What is the purpose of the continue statement in a loop?
To skip the current iteration and continue with the next
To stop the loop completely
To exit the loop if a condition is met
To restart the loop from the beginning
16
Multiple Choice
Which of the following is NOT a type of loop in Python?
while loop
for loop
nested loop
do-while loop
17
Multiple Choice
How do you define a for loop in Python?
for each item in sequence:
for item = sequence:
for (item in sequence):
for item in sequence:
18
Multiple Choice
What will the following code print? fruits = ['apple', 'banana', 'cherry']; for x in fruits: print(x)
apple banana cherry
banana cherry apple
cherry banana apple
apple, banana, cherry
19
Multiple Choice
What will the following code output? for x in 'banana': print(x)
b a n a n a
b a n
banana
b, a, n, a, n, a
20
Multiple Choice
What does the following code do? for x in fruits: if x == 'banana': break
It prints all fruits
It skips 'banana' and prints the rest
It stops the loop when 'banana' is found
It prints 'banana' only
21
Multiple Choice
What will the following code output? for x in 'banana': print(x)
b a n a n a
b a n
banana
b, a, n, a, n, a
22
Multiple Choice
What will happen if you use continue when x is 'banana' in the following code? for x in fruits: if x == 'banana': continue; print(x)
It will print 'banana'
It will skip 'banana' and print the rest
It will print nothing
It will cause an error
By Tempa Rinchen
Show answer
Auto Play
Slide 1 / 22
SLIDE
Similar Resources on Wayground
20 questions
Kewargaan Digital
Presentation
•
10th Grade
19 questions
FACTORIZACIÓN
Presentation
•
10th Grade
16 questions
[PROGDAS] Operator // 27082021
Presentation
•
10th Grade
18 questions
Word-basico
Presentation
•
9th Grade
17 questions
Literal Equations
Presentation
•
9th - 10th Grade
19 questions
Parts of the motherboard
Presentation
•
10th Grade
16 questions
Sex-linked traits
Presentation
•
10th Grade
17 questions
Fișiere text
Presentation
•
10th Grade
Popular Resources on Wayground
10 questions
How much do you know about our Portrait of an Eagle?
Quiz
•
10th Grade
10 questions
Fast Food Slogans
Quiz
•
6th - 8th Grade
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
16 questions
Subject & Predicate
Quiz
•
5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
12 questions
Map Skills
Quiz
•
3rd Grade
22 questions
Continents and Oceans
Quiz
•
5th Grade
Discover more resources for Computers
10 questions
Exploring Digital Citizenship Essentials
Interactive video
•
6th - 10th Grade
20 questions
[AP CSP] Python Coding: Functions, Parameters, Return
Presentation
•
9th - 12th Grade
40 questions
Introduction to Microsoft Word
Quiz
•
8th - 12th Grade
20 questions
APCS Unit 1A
Quiz
•
9th - 12th Grade
24 questions
Binary
Quiz
•
9th - 12th Grade