PYTHON PROGRAM THAT USES FOR LOOP TO PRINT THE NUMBERS 8,11,14,17,20,.........,83,86,89

 

Write a program that uses a for loop to print the numbers 8, 11, 14, 17, 20, . . . , 83, 86, 89.


SYNTAX OF FOR LOOP:

 for iterator_var in sequence:

        statement(s)

It can be used to iterate over a range and iterators.

RANGE() FUNCTION:

The range() function returns a sequence of numbers, starting from 0 by default, increments by 1 by default and stops before a specified number.

SYNTAX OF RANGE() FUNCTION:

range(start value,stop value,step count)

EXAMPLE:

range(5) --->0,1,2,3,4  ;  range(1,5) ---> 1,2,3,4 ;

range(1,7,2) --->1,1+2=3,3+2=5 -->1,3,5  


CODE:

for i in range(8,90,3):

    print(i,end=",")


EXPLANATION:

In this code the loop iterates over a range(8,90,3) i.e.,it prints 8 and then increments the value by 3.

It will continue this process until it reaches 89.

In the print statement end="," indicates that each number will be separated by comma in the output.


OUTPUT:






Comments

Popular posts from this blog

PYTHON PROGRAM THAT GENERATES A RANDOM NUMBER BETWEEN 1 AND 10 AND ASKS THE USER TO GUESS THE NUMBER

PYTHON PROGRAM THAT ASKS THE USER TO ENTER A WORD AND PRINTS OUT WHETHER THAT WORD CONTAINS ANY VOWELS