SlideShare a Scribd company logo
1 of 23
Repetition Structure
Chapter - 4
Introduction to Repetition Structures
Concept:
The repetition structure causes a
statement or set of statements to
execute repeatedly.
Introduction to Repetition Structures
Condition-Controlled and Count-Controlled
Loops
A condition-controlled loop uses a true/false
condition to control the number of times that it
repeats.
A count-controlled loop repeats a specific
number of times.
The while Loop:
a Condition-Controlled Loop
Concept:
A condition-controlled loop causes a
statement or set of statements to repeat
as long as a condition is true. In Python
you use the while statement to write a
condition-controlled loop.
The while Loop:
a Condition-Controlled Loop
In Python …
while condition:
statement
statement
etc.
Figure 4-1 The logic of a while loop
The while Loop:
a Condition-Controlled Loop
Figure 4-2 The while loop
The while Loop:
a Condition-Controlled Loop
The while Loop is a Pretest Loop,
which means it tests its condition before
performing an iteration.
The for Loop:
a Count-Controlled Loop
Concept:
A count-controlled loop iterates a specific
number of times. In Python you use the
for statement to write a count-controlled
loop.
The for Loop:
a Count-Controlled Loop
In Python …
for variable in [value1, value2, etc.]:
statement
statement
etc.
The for Loop:
a Count-Controlled Loop
Using the range Function with the for Loop
for num in [0, 1, 2, 3, 4]:
print num
for num in range(5):
print num
The for Loop:
a Count-Controlled Loop
Using the range Function with the for Loop
• First argument, 1, is the starting value for the list
• Second argument, 10, is the ending limit of the list
• Third argument, 2, is the step value
for num in range(1, 10, 2):
print num
The for Loop:
a Count-Controlled Loop
Program 4-12 (user_squares2.py)
The for Loop:
a Count-Controlled Loop
Generating Lists that Range from
Highest to Lowest
for num in range(5, 0, -1):
print num
Calculating a Running Total
Concept:
A running total is a sum of numbers that
accumulates with each iteration of a
loop. The variable used to keep the
running total is called an accumulator.
Calculating a Running Total
Programs that calculate the total of a series of
numbers typically use two elements:
•A loop that reads each number in the series
•A variable that accumulates the total of the
numbers as they are read.
Calculating a Running Total
Figure 4-7 Logic for calculating a running total
Calculating a Running Total
The Augmented Assignment Operators
Table 4-2 The age variable references the value 25
Sentinels
Concept:
A sentinel is a special value that marks
the end of a sequence of values.
Input Validation Loops
Concept:
Input validation is the process of
inspecting data that has been input to a
program, to make sure it is valid before it
is used in a computation. Input validation
is commonly done with a loop that
iterates as long as an input variable
references bad data.
Input Validation Loops
Error Trap or Error Handler
Figure 4-8 Logic containing an input validation loop
Input Validation Loops
Priming Read
# Get a test score.
Score = input(‘Enter a test score: ‘)
# Make sure it is not less than 0.
while score < 0:
print ‘ERROR: The score cannot be negative.’
score = input (‘Enter the correct score: ‘)
Nested Loops
Concept:
A loop that is inside another loop is
called a nested loop.
Nested Loops
About Nested Loops:
•The inner loop goes through all of its iterations for every single
iteration of the outer loop
•Inner loops complete their iterations faster than outer loops
for hours in range(24):
for minutes in range(60):
for seconds in range(60):
print hours, ‘:’, minutes, ‘:’,
seconds

More Related Content

What's hot (18)

SD & D Running Total
SD & D Running TotalSD & D Running Total
SD & D Running Total
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
Comp 220 ilab 6 of 7
Comp 220 ilab 6 of 7Comp 220 ilab 6 of 7
Comp 220 ilab 6 of 7
 
Java input Scanner
Java input Scanner Java input Scanner
Java input Scanner
 
Stack application
Stack applicationStack application
Stack application
 
Ppt lesson 06
Ppt lesson 06Ppt lesson 06
Ppt lesson 06
 
Finalproj
FinalprojFinalproj
Finalproj
 
Java Repetiotion Statements
Java Repetiotion StatementsJava Repetiotion Statements
Java Repetiotion Statements
 
Loops c++
Loops c++Loops c++
Loops c++
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
 
Looping
LoopingLooping
Looping
 
Introduction to SkyPat 2.0
Introduction to SkyPat 2.0Introduction to SkyPat 2.0
Introduction to SkyPat 2.0
 
C++ loop
C++ loop C++ loop
C++ loop
 
Ch07
Ch07Ch07
Ch07
 
Comp ppt (1)
Comp ppt (1)Comp ppt (1)
Comp ppt (1)
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
Python Training in Bangalore | Python Introduction Session | Learnbay
Python Training in Bangalore |  Python Introduction Session | LearnbayPython Training in Bangalore |  Python Introduction Session | Learnbay
Python Training in Bangalore | Python Introduction Session | Learnbay
 
Looping in c++
Looping in c++Looping in c++
Looping in c++
 

Similar to Introduction to Repetition Structures

Conditional Loops Python
Conditional Loops PythonConditional Loops Python
Conditional Loops Pythonprimeteacher32
 
Repetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniquesRepetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniquesJason J Pulikkottil
 
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docxransayo
 
JAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptxJAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptxJanCarlBriones2
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in CSowmya Jyothi
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingNeeru Mittal
 
Going loopy - Introduction to Loops.pptx
Going loopy - Introduction to Loops.pptxGoing loopy - Introduction to Loops.pptx
Going loopy - Introduction to Loops.pptxAmy Nightingale
 
Visula C# Programming Lecture 4
Visula C# Programming Lecture 4Visula C# Programming Lecture 4
Visula C# Programming Lecture 4Abou Bakr Ashraf
 
Intro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … WhileIntro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … WhileBlue Elephant Consulting
 
Gaddis Python 3e Chapter 04 PPT.ppt
Gaddis Python 3e Chapter 04 PPT.pptGaddis Python 3e Chapter 04 PPT.ppt
Gaddis Python 3e Chapter 04 PPT.pptFarahali78
 
etlplooping-170320213203.pptx
etlplooping-170320213203.pptxetlplooping-170320213203.pptx
etlplooping-170320213203.pptxffyuyufyfufufufu
 

Similar to Introduction to Repetition Structures (20)

Conditional Loops Python
Conditional Loops PythonConditional Loops Python
Conditional Loops Python
 
Repetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniquesRepetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniques
 
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
 
Ch05
Ch05Ch05
Ch05
 
Decision making and looping
Decision making and loopingDecision making and looping
Decision making and looping
 
JAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptxJAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptx
 
Programming loop
Programming loopProgramming loop
Programming loop
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in C
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop working
 
Loops in C.pptx
Loops in C.pptxLoops in C.pptx
Loops in C.pptx
 
03b loops
03b   loops03b   loops
03b loops
 
Loops
LoopsLoops
Loops
 
Going loopy - Introduction to Loops.pptx
Going loopy - Introduction to Loops.pptxGoing loopy - Introduction to Loops.pptx
Going loopy - Introduction to Loops.pptx
 
Ppt chapter04
Ppt chapter04Ppt chapter04
Ppt chapter04
 
Pptchapter04
Pptchapter04Pptchapter04
Pptchapter04
 
Visula C# Programming Lecture 4
Visula C# Programming Lecture 4Visula C# Programming Lecture 4
Visula C# Programming Lecture 4
 
Intro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … WhileIntro To C++ - Class 12 - For, do … While
Intro To C++ - Class 12 - For, do … While
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Gaddis Python 3e Chapter 04 PPT.ppt
Gaddis Python 3e Chapter 04 PPT.pptGaddis Python 3e Chapter 04 PPT.ppt
Gaddis Python 3e Chapter 04 PPT.ppt
 
etlplooping-170320213203.pptx
etlplooping-170320213203.pptxetlplooping-170320213203.pptx
etlplooping-170320213203.pptx
 

More from Munazza-Mah-Jabeen (20)

Virtual Functions
Virtual FunctionsVirtual Functions
Virtual Functions
 
The Standard Template Library
The Standard Template LibraryThe Standard Template Library
The Standard Template Library
 
Object-Oriented Software
Object-Oriented SoftwareObject-Oriented Software
Object-Oriented Software
 
Templates and Exceptions
 Templates and Exceptions Templates and Exceptions
Templates and Exceptions
 
Dictionaries and Sets
Dictionaries and SetsDictionaries and Sets
Dictionaries and Sets
 
More About Strings
More About StringsMore About Strings
More About Strings
 
Streams and Files
Streams and FilesStreams and Files
Streams and Files
 
Lists and Tuples
Lists and TuplesLists and Tuples
Lists and Tuples
 
Files and Exceptions
Files and ExceptionsFiles and Exceptions
Files and Exceptions
 
Functions
FunctionsFunctions
Functions
 
Pointers
PointersPointers
Pointers
 
Inheritance
InheritanceInheritance
Inheritance
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Arrays and Strings
Arrays and StringsArrays and Strings
Arrays and Strings
 
Objects and Classes
Objects and ClassesObjects and Classes
Objects and Classes
 
Functions
FunctionsFunctions
Functions
 
Structures
StructuresStructures
Structures
 
Loops and Decisions
Loops and DecisionsLoops and Decisions
Loops and Decisions
 
C++ programming basics
C++ programming basicsC++ programming basics
C++ programming basics
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 

Introduction to Repetition Structures

  • 2. Introduction to Repetition Structures Concept: The repetition structure causes a statement or set of statements to execute repeatedly.
  • 3. Introduction to Repetition Structures Condition-Controlled and Count-Controlled Loops A condition-controlled loop uses a true/false condition to control the number of times that it repeats. A count-controlled loop repeats a specific number of times.
  • 4. The while Loop: a Condition-Controlled Loop Concept: A condition-controlled loop causes a statement or set of statements to repeat as long as a condition is true. In Python you use the while statement to write a condition-controlled loop.
  • 5. The while Loop: a Condition-Controlled Loop In Python … while condition: statement statement etc. Figure 4-1 The logic of a while loop
  • 6. The while Loop: a Condition-Controlled Loop Figure 4-2 The while loop
  • 7. The while Loop: a Condition-Controlled Loop The while Loop is a Pretest Loop, which means it tests its condition before performing an iteration.
  • 8. The for Loop: a Count-Controlled Loop Concept: A count-controlled loop iterates a specific number of times. In Python you use the for statement to write a count-controlled loop.
  • 9. The for Loop: a Count-Controlled Loop In Python … for variable in [value1, value2, etc.]: statement statement etc.
  • 10. The for Loop: a Count-Controlled Loop Using the range Function with the for Loop for num in [0, 1, 2, 3, 4]: print num for num in range(5): print num
  • 11. The for Loop: a Count-Controlled Loop Using the range Function with the for Loop • First argument, 1, is the starting value for the list • Second argument, 10, is the ending limit of the list • Third argument, 2, is the step value for num in range(1, 10, 2): print num
  • 12. The for Loop: a Count-Controlled Loop Program 4-12 (user_squares2.py)
  • 13. The for Loop: a Count-Controlled Loop Generating Lists that Range from Highest to Lowest for num in range(5, 0, -1): print num
  • 14. Calculating a Running Total Concept: A running total is a sum of numbers that accumulates with each iteration of a loop. The variable used to keep the running total is called an accumulator.
  • 15. Calculating a Running Total Programs that calculate the total of a series of numbers typically use two elements: •A loop that reads each number in the series •A variable that accumulates the total of the numbers as they are read.
  • 16. Calculating a Running Total Figure 4-7 Logic for calculating a running total
  • 17. Calculating a Running Total The Augmented Assignment Operators Table 4-2 The age variable references the value 25
  • 18. Sentinels Concept: A sentinel is a special value that marks the end of a sequence of values.
  • 19. Input Validation Loops Concept: Input validation is the process of inspecting data that has been input to a program, to make sure it is valid before it is used in a computation. Input validation is commonly done with a loop that iterates as long as an input variable references bad data.
  • 20. Input Validation Loops Error Trap or Error Handler Figure 4-8 Logic containing an input validation loop
  • 21. Input Validation Loops Priming Read # Get a test score. Score = input(‘Enter a test score: ‘) # Make sure it is not less than 0. while score < 0: print ‘ERROR: The score cannot be negative.’ score = input (‘Enter the correct score: ‘)
  • 22. Nested Loops Concept: A loop that is inside another loop is called a nested loop.
  • 23. Nested Loops About Nested Loops: •The inner loop goes through all of its iterations for every single iteration of the outer loop •Inner loops complete their iterations faster than outer loops for hours in range(24): for minutes in range(60): for seconds in range(60): print hours, ‘:’, minutes, ‘:’, seconds