
loops - modifying and looping
Authored by thanga_palani_ thanga_palani_
Computers
University

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
15 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What does for item in list: do?
Deletes items
Changes items
Loops through each item
Sorts list
Answer explanation
The statement 'for item in list:' is used to loop through each item in the list, allowing you to perform actions on each element. This makes 'Loops through each item' the correct choice.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which method gives number of items in a list?
size()
count()
length()
len()
Answer explanation
The correct method to get the number of items in a list in Python is 'len()'. The other options, 'size()', 'count()', and 'length()', are not valid for this purpose.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output?
nums = [1, 2, 3]
for i in range(len(nums)):
nums[i] += 5
print(nums)
[1, 2, 3]
[6, 7, 8]
[5, 5, 5]
[10, 20, 30]
Answer explanation
The loop iterates over each element in nums, adding 5 to each. After the loop, nums becomes [6, 7, 8]. Thus, the correct output is [6, 7, 8].
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the purpose of range(len(list))?
To loop through values
To get indexes
To reverse a list
To sort a list
Answer explanation
The expression range(len(list)) generates a sequence of indexes for the elements in the list. This allows you to access each element by its index, making it useful for iterating through the list while knowing the position of each item.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output?
data = ["a", "b", "c"]
for i in range(len(data)):
data[i] = data[i].upper()
print(data)
['a', 'b', 'c']
['A', 'B', 'C']
['A', 'b', 'C']
Error
Answer explanation
The code iterates through the list 'data' and converts each element to uppercase using the 'upper()' method. Thus, the output will be ['A', 'B', 'C'], making this the correct choice.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Can you use for loop to modify a list directly?
No
Yes, with index
Only with append
Only with remove
Answer explanation
Yes, you can use a for loop with an index to modify a list directly. This allows you to access and change elements at specific positions within the list.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output?
lst = [3, 6, 9]
for i in range(len(lst)):
lst[i] *= 2
print(lst)
[3, 6, 9]
[6, 12, 18]
v
Error
Answer explanation
The code iterates through the list 'lst' and multiplies each element by 2. The original list [3, 6, 9] becomes [6, 12, 18] after the operation. Therefore, the correct output is [6, 12, 18].
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
15 questions
Fundamentals of Algorithms - Unit 1 - Test 1
Quiz
•
University
19 questions
DBMS - Fundamentals
Quiz
•
University
17 questions
Kiến thức về trang tính
Quiz
•
7th Grade - University
10 questions
python quiz
Quiz
•
6th Grade - Professio...
16 questions
E-Commerce
Quiz
•
University - Professi...
20 questions
Control Structures C#
Quiz
•
University
20 questions
jak dobrze znasz Minecraft?
Quiz
•
1st Grade - Professio...
12 questions
Quiz No. 2.2 Hash Tables
Quiz
•
University
Popular Resources on Wayground
7 questions
History of Valentine's Day
Interactive video
•
4th Grade
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
15 questions
Valentine's Day Trivia
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
Discover more resources for Computers
18 questions
Valentines Day Trivia
Quiz
•
3rd Grade - University
12 questions
IREAD Week 4 - Review
Quiz
•
3rd Grade - University
23 questions
Subject Verb Agreement
Quiz
•
9th Grade - University
5 questions
What is Presidents' Day?
Interactive video
•
10th Grade - University
7 questions
Renewable and Nonrenewable Resources
Interactive video
•
4th Grade - University
20 questions
Mardi Gras History
Quiz
•
6th Grade - University
10 questions
The Roaring 20's Crash Course US History
Interactive video
•
11th Grade - University
17 questions
Review9_TEACHER
Quiz
•
University