In Python, you can use the range()
function with the decrement step size of -1
inside a for
loop to iterate over a sequence of numbers in reverse order from 10
to 5
. Here's how you can do it:
main.py44 chars3 lines
In the range()
function, the first argument represents the starting number of the sequence, the second argument represents the ending number of the sequence (exclusive), and the third argument represents the step size. By setting the step size to -1
, we make the sequence count down from 10
to 5
. Then, we use a for
loop to iterate over each number in the sequence and print it to the console.
gistlibby LogSnag