CP104 - Chapter 4 - Repetition Structures
CP104 - Chapter 4 - Repetition Structures
keep_going = 'y'
This program demonstrates an infinite loop. # Create a variable to control the loop. keep_going
= 'y'
statement
statement
etc.
#This program demonstrates a simple for loop that uses a list of numbers.
Program Output
1
2
print(num)
Sentinels
A sentinel is a special value that marks the end of a sequence of values.
Input Validation
Input validation is the process of inspecting data that has been input to
RETAIL PRICES
# This program calculates retail prices.
MARK_UP = 2.5 # The markup percentage
another = 'y' # Variable to control the loop.
# Do this again?
another = input('Do you have another item? ' +
'(Enter y for yes): ')
Nested Loops
# This program averages test scores. It asks the user for the number of students and the
number of test scores per student.
total = 0.0