Class 9 – Monday, September 16
Lest we go forward — Without knowing about lists — We would be wanting
Look both ways
Agenda
- Introduce randomness
- Introduce
for
loop
- Introduce lists
Downloads
- Program love_is_all_you_need.py
- Program amore.py
- Program ready_or_not.py
- Program again_and_again.py
- Program kinda_stringy.py
To do list
- Review class artifacts.
- Read the epistle on lists.
- Check out my documentation for the
random
module.
- Check out my documentation for the
list
module.
Example to motivate looping
- Program love_is_all_you_need.py
- Let's print out one-line-at-a-time, a bunch of the phrase Love is all you need
Examples to introduce looping
- Program amore.py
- Prints out a user-supplied string list of words, one by one
Some program runs
Enter three words: am or e
am
or
e
Enter a list of words: amor mapenzi amour liebe rakkaus
amor
mapenzi
amour
liebe
rakkaus
Enter three words: abcd efg hijklm
abcd
efg
hijklm
Enter a list of words: ljubav aroha ghaoil uthando
ljubav
aroha
ghaoil
uthando
- 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!'
- Some program runs
Enter a number: 10
0 Mississippi
1 Mississippi
2 Mississippi
3 Mississippi
4 Mississippi
5 Mississippi
6 Mississippi
7 Mississippi
8 Mississippi
9 Mississippi
Ready or not here I come!
Enter a number: 15
0 Mississippi
1 Mississippi
2 Mississippi
3 Mississippi
4 Mississippi
5 Mississippi
6 Mississippi
7 Mississippi
8 Mississippi
9 Mississippi
10 Mississippi
11 Mississippi
12 Mississippi
13 Mississippi
14 Mississippi
Ready or not here I come!
- Program again_and_again.py
- Prints a requested phrase a requested number of times
- Some program runs
Enter string to be printed: one more time
Enter number of times to be printed: 5
one more time
one more time
one more time
one more time
one more time
Enter string to be printed: I said how are you today
Enter number of times to be printed: 10
I said how are you today
I said how are you today
I said how are you today
I said how are you today
I said how are you today
I said how are you today
I said how are you today
I said how are you today
I said how are you today
I said how are you today
Going through a string
- Program kinda_stringy.py
- Prints out the characters of two user-supplied strings, character by character. The first without a loop, the second with a loop.
Enter a three-letter string: abc
a
b
c
Enter a string: four score and seven
f
o
u
r
s
c
o
r
e
a
n
d
s
e
v
e
n
Enter a three-letter string: def
d
e
f
Enter a string: years ago our
y
e
a
r
s
a
g
o
o
u
r
Counting sheep
© 2019 Jim Cohoon | Resources from previous semesters are available. |