Practice The for Loop - 5.2 | 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

The for Loop

5.2 - The for Loop

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

Write a for loop to print all numbers from 1 to 5.

💡 Hint: Use range from 1 to 6 to include 1 to 5.

Question 2 Easy

Create a for loop that prints characters from a string 'hello'.

💡 Hint: You can use the string directly as the sequence.

4 more questions available

Interactive Quizzes

Quick quizzes to reinforce your learning

Question 1

What is the output of the following code?

Code Editor - python
0
1
2
0
1
2
3
1
2
3

💡 Hint: Consider the starting point and how many numbers are produced by range.

Question 2

True or False: The for loop can iterate only through lists.

True
False

💡 Hint: Recall other sequences that can be iterated.

Get performance evaluation

Challenge Problems

Push your limits with advanced challenges

Challenge 1 Hard

Create a program that uses a for loop to find the factorial of numbers from 1 to 5.

💡 Hint: Remember that factorial is the product of all positive integers up to that number.

Challenge 2 Hard

Construct a for loop that generates the Fibonacci sequence up to 100.

💡 Hint: Keep track of the last two Fibonacci numbers and update them in each iteration.

Get performance evaluation

Reference links

Supplementary resources to enhance your learning experience.