Class 10 – Wednesday, February 6
Being loopy
Being random for a loop
You did not expect – The repetition to come – You did not expect
Look both ways
Agenda
- Doing loop the loops
Examples
- Program again_and_again.py
- Let's print out a requested phrase a requested number of times
- Program ready_or_not.py
- Prints out the integers 0 to
n
-1 for user-suppliedn
; afterwards, prints out the phrase'Ready or not here I come!'
- Program blast_off.py
- Prints a user-requested count down and then prints the phrase
'Blast off!'
- Program bit_by_bit.py
- Generates a list of
n
bits (binary digits) for a user-suppliedn
.
- Program octane.py
- Prompts and gets three user-supplied integers
s
,n
, andd
. Uses integers
as a seed to the Python random number generator.
- Accumulates a list of
n
octal digits (base 8 digits) one by one. Afterwards, prints the list of octal digits.
- Determines and prints the number of occurrences of
d
in the list of octals (check out the list module for a helpful function.
- Two program runs
Enter three numbers: 1112 12 1
[4, 1, 4, 0, 6, 1, 5, 2, 5, 1, 1, 2]
4
Enter three numbers: 8 9 6
[3, 5, 6, 2, 3, 0, 1, 2, 3]
1
- Homework program in_summation.py
- Performs the following tasks to process a user-specified list of integer values
- Prompts and gets as input an integer list of numbers
- Converts the input into a list of numeric strings
- By accumulation, converts the numeric strings one-by-one to get a list of integers (a loop is needed)
- By accumulation, gets the total of the integer list values one-by-one (a loop is needed)
- Prints the integer list
- Prints the total
- Two possible program runs
Enter a list of integers: 3 5 9 13
[3, 5, 9, 13]
30
Enter a list of integers: 2 -7 9 88
[2, -7, 9, 88]
92
To do list
- Review class artifacts.
- Complete the in_summation.py as homework by Friday 2PM.