Class 11 – Friday, February 8
In a loop, a loop — Nesting, but not like a bird — Repeating again
You did not expect – The repetition to come – You did not expect
Look both ways
Agenda
- Extend
print()
function functionality
- Introduce the
time
module
- Doing loop the loops
- Introduce the pillow.
Problems
-
Program thats_printastic.py
- Introduces the optional closing parameter
end="..."
Wa-Hoo-Wa
Rah-Rah-Rah
Wa-Hoo-Wa!!!Rah-Rah-Rah
Wa-Hoo-Wa !!! Rah-Rah-Rah
t-a-t-t-a-r-r-a-t-t-a-t-
saippuakivikauppias
-
Program nested_looper.py
- Introduces nested looping. Where for a user-supplied
n
, the program loopsn
times and on thei
th iteration prints a line of the form
i: 0 1 2 ... i
- Two sample program runs
Enter number: 5
0: 0
1: 0 1
2: 0 1 2
3: 0 1 2 3
4: 0 1 2 3 4
Enter number: 12
0: 0
1: 0 1
2: 0 1 2
3: 0 1 2 3
4: 0 1 2 3 4
5: 0 1 2 3 4 5
6: 0 1 2 3 4 5 6
7: 0 1 2 3 4 5 6 7
8: 0 1 2 3 4 5 6 7 8
9: 0 1 2 3 4 5 6 7 8 9
10: 0 1 2 3 4 5 6 7 8 9 10
11: 0 1 2 3 4 5 6 7 8 9 10 11
-
Program vowely.py
- Gets a single word from the user and separately reports its length and its number of vowels
- Two sample program runs
Enter a word: subbookkeeper
length: 13
vowels: 66
Enter a word: supercalifragilisticexpialidocious
length: 34
vowels: 16
-
Program grabby.py
- Separately prompt for a string
s
and a list of integersnumbers
. The program displays the string formed by usingnumbers
as indices intos
.
- For example, suppose
s
equals'abcdefghijklmnopqrstuvwxyz-'
andnumbers
equals[ 4, 8, 26, 4, 8, 26, 14 ]
the output is the string'ei-ei-o'
, becauses[ 4 ]
equals'e'
,s[ 8 ]
equals'i'
,s[ 14 ]
, equals'o'
, ands[ 26 ]
equals'-'
. There should be no other output.
- Two sample program runs with preferred form of output
Enter string: computer
Enter list of indices: 5 1 7
tor
Enter string: gosh look what the cat is up to now
Enter list of indices: 24 5 17 17 27 23 32 0
sleeping
- Two sample program runs whose output form is acceptable for today
Enter string: computer
Enter list of indices: 5 1 7
t
o
r
Enter string: gosh look what the cat is up to now
Enter list of indices: 24 5 17 17 27 23 32 0
s
l
e
e
p
i
n
g
To do list
- Install pillow.
- Reveal one of your super power(s)
- Share a selfie
- Review class artifacts.
- Complete the aeschylus.py homework by Monday 2PM.