Class 8 – Friday, September 11

I know that or now I know that, that is the question

We are humankind — What a mantra that could be — I'm human and kind

A name is needed — For our class's string mascot — Have you an idea?



Look both ways


Request


What I want to accomplish today


Downloads

 

 


To do list


Problem solving — program prowess.py

Two possible program runs

Enter text: Hoos got your back

Input length: 18

Index of last input character: 17

Last character in text: k

Enter text: Enter text: And the winner is ...

Input length: 21

Index of last input character: 20

Last input character: .



Program case_by_case.py

A possible program run

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

A possible program run

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

A possible program run

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

A possible program run

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): e

Enter substring (r):

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



Program slice_of_pie.py

Two possible program runs

Enter favorite pie: anchovies and garlic

Enter two indices: 3 15

s: anchovies and garlic

i: 3

j: 15

s[ i ]: h

s[ j ]: a

s[ i : j ]: hovies and g

s[ i : ]: hovies and garlic

s[ : j ]: anchovies and g

s[ : ]: anchovies and garlic

Enter favorite pie: strawberry rhubarb

Enter two indices: 12 14

s: strawberry rhubarb

i: 12

j: 14

s[ i ]: h

s[ j ]: b

s[ i : j ]: hu

s[ i : ]: hubarb

s[ : j ]: strawberry rhu

s[ : ]: strawberry rhubarb



Program kinda_stringy.py

Two possible program runs

Enter a three-letter string: abc

a

b

c

Enter a string: four score

f

o

u

r

s

c

o

r

e

Enter a three-letter string: def

d

e

f

Enter a string: and seven years

a

n

d

f

o

u

r

y

e

a

r

s



Program again_and_again.py

Two possible program runs

Enter string to be printed: one more time

Enter number of times to be printed: 3

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: 5

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



Program shifty.py

Two possible program runs

Enter three strings: a b c

Before the shift w1, w2, and w3 are respectively: a b c

After the shift w1, w2, and w3 are respectively: c a b

Enter three strings: kiwi cucumber nectarine

Before the shift w1, w2, and w3 are respectively: kiwi cucumber nectarine

After the shift w1, w2, and w3 are respectively: nectarine kiwi cucumber




{{Information |Description=Whitecliffs, Canterbury, New Zealand |Source=flickr.com ([http://www.flickr.com/photos/flissphil/148026511/]) |Date=16 May 2006 |Author=Phillip Capper |Permission= |other_versions= }}


 


  © 2020 Jim Cohoon   Resources from previous semesters are available.