Class 08 – Friday, September 09

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

Climate change is real — Science is truth, not fake news — Help save the future


Look both ways


What I want to accomplish today


Downloads

 


To do list


Program dashes.py

50 * - is --------------------------------------------------

- * 50 is --------------------------------------------------



Program escaping.py

a: a b c d

b: "Air quotes" are annoying

c: Hello

 

Goodbye

 

len( a ): x

len( a ): 7

len( b ): 25



Program finding.py

s: can anyone

  ----------

  0123456789 <== indices into s

t: an

s.find( t ): 1

s.find( t, 1 ): 4

s.find( t, 4 ): -1



Program cat.py

Enter three indices: 0 8 9

cat

Enter three indices: 13 1 3

she

Enter three indices: 2 8 7

ram



Program replacement.py

Enter text: hello mellow pillow

Enter substring (s): ll

Enter substring (r): L L

text.replace( s, r ): heL Lo meL Low piL Low # text’s s’s replaced with r’s

Enter text: jeepers creepers look at those peepers

Enter substring (s): eepers

Enter substring (r):

text.replace( s, r ): j cr look at those p # text’s s’s replaced with r’s



Program countability.py

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 slice_of_pie.py

Enter favorite pie: chocolate

Enter two indices i and j: 3 8

s[ i : j ]: colat

s[ i : ]: colate

s[ : j ]: chocolat

s[ : ]: chocolate

Enter favorite pie: pizza

Enter two indices i and j: 2 3

s[ i : j ]: z

s[ i : ]: zza

s[ : j ]: piz

s[ : ]: pizza

Enter favorite pie: garlic tart

Enter two indices i and j: 1 8

s[ i : j ]: arlic t

s[ i : ]: arlic tart

s[ : j ]: garlic t

s[ : ]: garlic tart



Program kinda_stringy.py

Enter text: four score

f

o

u

r

s

c

o

r

e

Enter text: step by step, inch by inch, Niagra Falls

s

t

e

p

b

y

s

t

e

p

,

i

n

c

h

b

y

i

n

c

h

N

i

a

g

r

a

F

a

l

l

s



Problem solving — program prowess.py

  • Prompt and get a line of text.
  • Determine and print the length of the text.
  • Determine and print the index of last character in the text.
  • Determine and print the last character of the text.
  • Prints its results.

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



Problem solving — program vowely.py

Enter text: Are you doing okay today?

a: 3

e: 1

i: 1

o: 4

u: 1

Enter text: Subbookkeeper is one of my favorite words (and I am not being faceious).

a: 4

e: 7

i: 5

o: 8

u: 2

Enter text: Is rural juror a tongue twister?

a: 2

e: 2

i: 2

o: 2

u: 3

Enter text: tsk-tsk

a: 0

e: 0

i: 0

o: 0

u: 0



{{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= }}