What is the output for the following code?
for i in range(2)
print(i)
Grok Module 6 Practice

Flashcard
•
Computers
•
7th - 8th Grade
•
Hard
Quizizz Content
FREE Resource
Student preview

8 questions
Show all answers
1.
FLASHCARD QUESTION
Front
Back
Syntax Error
Answer explanation
The code has a syntax error due to a missing closing quote at the end of the for loop. Therefore, 'Syntax Error' is the correct answer.
2.
FLASHCARD QUESTION
Front
The code repeats twice. Which "for" loop would I use if I wanted to rewrite this code using a "for" loop? Options: for i in range(1), for i in range(3), for i in range(2):, Can not write it as a loop
Back
for i in range(2):
Answer explanation
The following code repeats twice:
turtle.forward(100)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
The for loop for twice is:
for i in range(2)
which counts 0 and then 1 and stops
3.
FLASHCARD QUESTION
Front
What is the output?
for i in range(3)
#print(i+1)
Back
Nothing will print
Answer explanation
Nothing will print out since the print statement is commented out using the #
4.
FLASHCARD QUESTION
Front
What letter is in name[-2] for Ms. Allie Parham?
Back
a
Answer explanation
name[-2] counts 2 from the end of the string so the solution is "a"
5.
FLASHCARD QUESTION
Front
What is the correct "for" loop to use? Options: from turtle import * for i in range(5): forward(50) right(90), from turtle import * for i in range(3): forward(50) right(90), from turtle import * for i in range(4): forward(50) right(90)
Back
from turtle import * for i in range(4): forward(50) right(90)
Answer explanation
a range(n) function goes 0 up to n but does not include n. Therefore, range(4) goes from 0 to 3 but does not include the 4. If you want it to run 4 times you need range(4).
6.
FLASHCARD QUESTION
Front
What is the last value printed in the following code?
loop_counter = 3
for k in range(loop_counter):
print(k)
Back
2
Answer explanation
range(n) goes from 0 to n but does not include n. Therefore, range(3) will print 0,1,2 but not 3
7.
FLASHCARD QUESTION
Front
What is the correct way to replace the code with a "for" loop? Options: for 'grok' in letter: print(letter), for letter in 'grok': print(grok), for letter in 'grok': print(letter), for 'grok': print(letters)
Back
for letter in 'grok':
print(letter)
Answer explanation
The correct syntax is:
for <where to store each letter> in <the word>
for letter in 'dog':
This will loop through each letter in the word dog.
8.
FLASHCARD QUESTION
Front
What is the output of the following code?
word = 'cat' for letter in word: print("letter") Note: The output will print one letter per line
Back
letter
Answer explanation
Normally this would print the letters in the word cat with one letter on each line. There are quotes around the word "letter" so it will print the string letter.
Similar Resources on Quizizz
6 questions
Code.org Express Course -> Lesson 12

Flashcard
•
5th - 8th Grade
10 questions
Python Inputs

Flashcard
•
7th - 8th Grade
10 questions
Lesson 11: Loops with Rey and BB-8

Flashcard
•
6th Grade
11 questions
KS3 - Programming Key terms

Flashcard
•
8th Grade
11 questions
Python Basics Flashcard

Flashcard
•
8th Grade
8 questions
NF Persuasive Writing Vocabulary

Flashcard
•
6th - 8th Grade
8 questions
End of Unit 3 Review

Flashcard
•
8th Grade
8 questions
Python Flashcard - ForLoops CS1

Flashcard
•
9th Grade
Popular Resources on Quizizz
15 questions
Character Analysis

Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing

Quiz
•
9th - 12th Grade
10 questions
American Flag

Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension

Quiz
•
5th Grade
30 questions
Linear Inequalities

Quiz
•
9th - 12th Grade
20 questions
Types of Credit

Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25

Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers

Quiz
•
6th - 8th Grade
Discover more resources for Computers
14 questions
Misplaced and Dangling Modifiers

Quiz
•
6th - 8th Grade
17 questions
Parts of Speech

Quiz
•
7th - 12th Grade
11 questions
Decimal/fraction conversions quick check

Quiz
•
5th - 7th Grade
10 questions
Identifying equations

Quiz
•
KG - University
44 questions
El fin del año- 7th

Quiz
•
7th - 12th Grade
40 questions
Word Study Assessment: Roots, Prefixes, Suffixes, and Vocabulary

Quiz
•
8th Grade
17 questions
guess the logo

Quiz
•
8th Grade
16 questions
Function or Non-Function?

Quiz
•
8th - 10th Grade