Class 9 – Monday, February 3

Do that again

Did you not expect – The repetition to come – Did you not expect


Look both ways


Agenda


Word of the day


Downloads


To do list


Program wordy.py — examines a list of user-supplied words and reports their lengths

Enter text: All hoos got your back

Supplied text = All hoos got your back

words = ['All', 'hoos', 'got', 'your', 'back']

All : 3

hoos : 4

got : 3

your : 4

back : 4

Enter text: It was a dark and stormy night

Supplied text = It was a dark and stormy night

words = ['It', 'was', 'a', 'dark', 'and', 'stormy', 'night']

It : 2

was : 3

a : 1

dark : 4

and : 3

stormy : 6

night : 5

Enter text:

Supplied text =

words = []

Enter text: Everyone has the right to education

Supplied text = Everyone has the right to education

words = ['Everyone', 'has', 'the', 'right', 'to', 'education']

Everyone : 8

has : 3

the : 3

right : 5

to : 2

education : 9

Average word length: 5.0



Program m_and_ns.py — prints a user-specified upward interval of numbers

Enter start and end: 2 7

2

3

4

5

6

7

Enter start and end: 4 8

4

5

6

7

8



Program n_and_ms.py — prints a user-specified downward interval of numbers

Enter start and end: 10 1

10

9

8

7

6

5

4

3

2

1

Enter start and end: 12 11

12

11



Program case_by_case.py — introduces string case functions capitalize(), lower(), and upper()

Enter text: thanks VERY mucH.

text: thanks VERY mucH.

text.lower() = thanks very much. # all lower case

text.upper() = THANKS VERY MUCH. # all upper case

text.capitalize() = Thanks very much. # initial character capitalized, rest lower case



Program countability.py — introduces string function count()

Enter text: any bananas

Enter substring: an

Enter index: 7

text.count( substring ) = 3 # count all

text.count( substring, 7 ) = 1 # count starting from index 7



Program find_the_spot.py — introduces string member function find()

Enter text: aardvark

Enter substring: a

text.find( substring ): 0 # first occurrence

text.find( substring, 1 ): 1 # second occurrence

text.find( substring, 2 ): 5 # third occurrence



Program replacement.py — introduces string function replace()

Enter text: yellow bellied sapsucker

Enter substring (s): ll

Enter substring (r): L L

text.replace( s, r ): yeL Low beL Lied sapsucker # text's s's replaced with r's

Enter text: yellow bellied sapsucker

Enter substring (s): l

Enter substring (r):

text.replace( s, r ): yllow bllid sapsuckr # text's s's replaced with r's



I can smile, see

scary person

Schrödinger' cat

cat in a box

 


 
  © 2020 Jim Cohoon   Resources from previous semesters are available.