0% found this document useful (0 votes)
25 views7 pages

Chapter 6 Repeatition

Uploaded by

nirattisaikul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views7 pages

Chapter 6 Repeatition

Uploaded by

nirattisaikul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Chapter 6 Repetition Structure

For loop

A for loop is a Python statement which repeats a block of code a specified number of
times.
Range!

the built-in function range (start,stop, step)

It generates lists containing arithmetic progressions.

The list can be not only the numbers, but also something else.
Range (omitting Step)!

For in Range

Range (omitting Start and Step)!

Note that range command doesn’t accept floating point and string parameters
Nested-For
While Loop!

A while loop statement in Python programming language repeatedly executes target


statement as long as a given condition is true.

Random

We can get all the functionalities in the module into our program by importing it with
import command.

import random

randint(a,b) The function will return a random integer number that are in between a
and b, inclusively.

By calling x = random.randint(1, 100), x will be a random number between 1 - 100.

The following example shows simple structure of the while loop. The condition (5>4) is
always true, so the word “Superman” will be printed infinitely.!

You might also like