Question

# Using a for loop and range command, print the sequence of numbers from 1 to 20...

Using a for loop and range command, print the sequence of numbers from 1 to 20 (skipping two numbers for each element); that is, your code should print out the numbers 1,4, 7, 10, … (max should not exceed 20). Use x as the variable name

In python programming language, we can print sequence of numbers using for loop and range command.

Given data,

Input: Numbers from 1 to 20

Output: sequence of numbers 1,4,7,10....

Condition: output should not exceed 20 and skipping two numbers for each element.

Program:

# consider variable name as x

for x in range(1,20+1,3):

print(x)

Explanation:

we have to give 20+1 because range considers the given number with -1. It means if we have given as 20 it considers the value upto 19 only. So inorder to print upto 20 give as 20+1.

The syntax for range is :

range(start value, stop value, increment steps)

In our code, range starts from 1 and ends with 20 with increment of 3 steps.

#### Earn Coins

Coins can be redeemed for fabulous gifts.