Course Content
Python Loops Tutorial
Python Loops Tutorial
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).
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.
Thanks for your feedback!
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).
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.
Thanks for your feedback!