PRO511-Chapter 4 Lecture Notes
PRO511-Chapter 4 Lecture Notes
Learning Outcomes
4.1 Introduction
Repetition structures, also known as looping structures, allow you to repeat a set of instructions
multiple times. There are two main types of looping structures in Python: for loops and while
loops.
Repetition structures (loops) allow you to execute a block of code multiple times. Python has
two types of loops:
• For loops: Used to iterate over a sequence (such as a list, tuple, or string) or any iterable
object, executing a block of code for each item.
• While loops: Used to repeatedly execute a block of code as long as a given condition
remains true.
Syntax:
count = 0
print(count)
count += 1
Output:
0
1
keep_going = 'y'
Syntax:
statement
Example:
print(num)
Syntax:
statement
Example:
print(num)
Example:
numbers = [5, 3, 7, 2, 8]
running_total = 0
running_total += number
4.7 Sentinels
TAX_FACTOR = 0.0065
while lot != 0:
Syntax:
Summary