Skip to content

Chunk d quiz


โœ๏ธ Quiz: Understanding loops

Solve the quizzes below to check what you learned! ๐ŸŽฏ

If you're not sure, read it again and give it a try! You've got this! ๐Ÿ’ช

Quiz 1: The loop keyword

Quiz: The loop keyword
What keyword starts a loop?
Hint: Enter the keyword you learned in this lesson.
Show Answer

Answer: for โœ…

for starts a loop with this keyword! ๐ŸŽฌ

for i in range(8):  # ๐ŸŽฌ The "start looping!" command
    print(i)        # ๐Ÿ  Code inside the room

for Next: - The variable name (i) ๐Ÿงบ - the basket - in - the connecting word - the range to loop over (range(8)) ๐Ÿญ - the number factory

The code inside a loop must be indented! ๐Ÿ 

Quiz 2: The range() function

Quiz: The range() function
range(5)which numbers does it make?
Show Answer

Answer: B) 0, 1, 2, 3, 4 โœ…

range(5)makes 5 numbers from the number factory, starting at 0! ๐Ÿญ

range(5)  # ๐Ÿญ 0, 1, 2, 3, 4 (5 total)

In Python, we start counting from 0! (0-based indexing) range(n)makes the numbers from 0 to n-1!

  • range(5) โ†’ 0, 1, 2, 3, 4 (5 numbers)
  • range(8) โ†’ 0, 1, 2, 3, 4, 5, 6, 7 (8 numbers)

Quiz 3: Indentation

Quiz: indentation
How should the code inside a loop be written in Python?
Show Answer

Answer: A) It must be indented โœ…

Indentation is very important in Python! The code inside a loop must always be indented! ๐Ÿ 

# Correct way โœ…
for i in range(3):
    print(i)      # ๐Ÿ  Inside the room, so it repeats

# Wrong way โŒ
for i in range(3):
print(i)  # ๐Ÿšช Outside the room, so it errors!

If you don't indent, an error, IndentationErroroccurs! ๐Ÿ˜“

Remember: Only the code inside the loop's room repeats! ๐Ÿ 

Quiz 4: Number of repetitions

Quiz: Number of repetitions
for i in range(8):how many times does it repeat?
Hint: Enter a number.
Show Answer

Answer: 8 โœ…

range(8)makes 8 numbers from the number factory, 0 to 7, so the loop runs 8 times! ๐Ÿญ๐Ÿ”„

for i in range(8):  # ๐Ÿ”„ Repeats 8 times
    print(i)        # ๐Ÿงบ Prints 0, 1, 2, 3, 4, 5, 6, 7

range(n)repeats exactly n times!

  • range(3) โ†’ repeats 3 times (0, 1, 2)
  • range(5) โ†’ repeats 5 times (0, 1, 2, 3, 4)
  • range(8) โ†’ repeats 8 times (0, 1, 2, 3, 4, 5, 6, 7)

Next step

Congratulations! ๐ŸŽŠ You now understand loops!

You learned how to repeat the same code by spinning like a carousel! ๐ŸŽ 

In the next lesson: - You'll learn how to use a list to store many objects ๐Ÿ“ฆ - You'll learn how to use lists and loops together ๐Ÿ”„

๐ŸŽฎ Try it yourself!

Experiment by changing the number in the number factory! ๐Ÿญ

range(8)the range(10)or range(5)Try changing it to this and see what happens! When the number of repetitions changes, the number of cubes made changes too!

for i in range(10):  # ๐Ÿญ Change from 8 to 10
    Entity(...)      # ๐Ÿ“ฆ Now 10 cubes are made!

Editing the code yourself and checking the results is the best way to learn! ๐Ÿ’ช

๐Ÿงฉ Reviewing the Object concept
  • An object is a LEGO blockLike this, it's an entity that has both properties and behaviors. ๐Ÿงฉ
  • A variable is sticky note ๐Ÿท๏ธ, and functions are Instruction manual for behaviors, and an object is a toy that combines the two.
  • Ursina's Entity is an object too!
  • Properties: model, color, scale (settings decided at birth) ๐ŸŽจ
  • Behaviors: animate_position() (actions it can do later) ๐ŸŽฌ
  • Putting objects into a list gives you a basketit becomes. ๐Ÿ—‚๏ธ