Course Content
Python Loops Tutorial
Python Loops Tutorial
4. List and Dictionary Comprehensions
Challenge: Exploring Steps and Reverse with range()
The range()
function generates a sequence of numbers and is often used in loops for controlled iteration. Its syntax is:
start
: The number where the sequence begins (default is 0);end
: The number where the sequence stops (not included);step
: The increment (or decrement) between numbers (default is 1).
Task
Swipe to show code editor
- Write a program to print every second city from the travel list (use
step = 2
inrange()
). - Write a program to print the last three cities in reverse order.
Solution
Switch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?
Thanks for your feedback!
Section 1. Chapter 3
Challenge: Exploring Steps and Reverse with range()
The range()
function generates a sequence of numbers and is often used in loops for controlled iteration. Its syntax is:
start
: The number where the sequence begins (default is 0);end
: The number where the sequence stops (not included);step
: The increment (or decrement) between numbers (default is 1).
Task
Swipe to show code editor
- Write a program to print every second city from the travel list (use
step = 2
inrange()
). - Write a program to print the last three cities in reverse order.
Solution
Switch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?
Thanks for your feedback!
Section 1. Chapter 3
Switch to desktop for real-world practiceContinue from where you are using one of the options below