Question: Task 5 Explanation: To iterate ( go ) through a sequence of numbers we can use a for loop. For example, if we want to

Task 5
Explanation:
To iterate (go) through a sequence of numbers we can use a for loop.
For example, if we want to print all the numbers from 10 to 20 we can write:
for number in range (10,21):
print (number)
Here, the variable called number increases in value from 10 until it reaches a value at least as big as 21. Please note that 21 is the first number that will not be printed.
In general, if we want to print all the numbers from the start to the end of a range, we can implement:
for number in range(start, end +1) :
print (number)
If we want to use a step value other than 1, we can add a third parameter to range.
For example, the following code prints even numbers (10,12,14,16,18,20):
for number in range (10,21,2) :
print (number)
Here is another example of printing numbers, this time from 10 to 1 is (in each iteration the variable number is decreased by 1):
for number in range (10,0,-1) :
print (number)
Please note that 0 is the first number that will not be printed.
Question:
Write a loop, that prints all odd numbers from 99 to 1(99,97,95,...,3,1).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!