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
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 to we can write:
for number in range :
print number
Here, the variable called number increases in value from until it reaches a value at least as big as Please note that 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 rangestart end :
print number
If we want to use a step value other than we can add a third parameter to range.
For example, the following code prints even numbers :
for number in range :
print number
Here is another example of printing numbers, this time from to is in each iteration the variable number is decreased by :
for number in range :
print number
Please note that is the first number that will not be printed.
Question:
Write a loop, that prints all odd numbers from to
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
