Practice Try It Yourself - 5.6 | Loops – for and while | Python Programming Language
Students

Academic Programs

AI-powered learning for grades 8-12, aligned with major curricula

Professional

Professional Courses

Industry-relevant training in Business, Technology, and Design

Games

Interactive Games

Fun games to boost memory, math, typing, and English skills

Try It Yourself

5.6 - Try It Yourself

Enroll to start learning

You’ve not yet enrolled in this course. Please enroll for free to listen to audio lessons, classroom podcasts and take practice test.

Learning

Practice Questions

Test your understanding with targeted questions

Question 1 Easy

Use a for loop to print numbers from 1 to 10.

💡 Hint: Use range with start and end values.

Question 2 Easy

What is the output of the following code: for i in range(5): print(i)?

💡 Hint: Think about the range function.

4 more questions available

Interactive Quizzes

Quick quizzes to reinforce your learning

Question 1

What does a for loop do?

Iterates over a sequence
Stops execution instantly
Only works with numbers

💡 Hint: Think about how loops operate in sequences.

Question 2

True or False: A while loop runs indefinitely if the condition is always true.

True
False

💡 Hint: Consider loop termination conditions.

1 more question available

Challenge Problems

Push your limits with advanced challenges

Challenge 1 Hard

Write a program that prints all prime numbers between 1 and 50 using a loop.

💡 Hint: Consider checking divisibility for each number.

Challenge 2 Hard

Create a while loop that prompts the user for input until they enter 'exit'.

💡 Hint: Think about how the condition can end the loop.

Get performance evaluation

Reference links

Supplementary resources to enhance your learning experience.