5 - Loops – for and while
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.
Practice Questions
Test your understanding with targeted questions
Print all numbers from 1 to 10 using a for loop.
💡 Hint: Use range function starting from 1 to 11.
Use a while loop to count down from 5 to 0.
💡 Hint: Start count at 5 and decrement.
4 more questions available
Interactive Quizzes
Quick quizzes to reinforce your learning
What does the 'break' statement do in a loop?
💡 Hint: Think about where the loop might stop.
True or False: A while loop will always execute at least once.
💡 Hint: Consider how a while loop starts.
3 more questions available
Challenge Problems
Push your limits with advanced challenges
Create a program using nested loops to output a triangle pattern of numbers (1 on the first line, 2 on the second, etc. up to 5 lines).
💡 Hint: The outer loop controls rows, and the inner loop controls printing spaces.
Write a Python program that prompts for a number and calculates its Fibonacci sequence up to that number using a while loop.
💡 Hint: Remember to update your previous numbers in the loop.
Get performance evaluation
Reference links
Supplementary resources to enhance your learning experience.