Class 08 – Friday February 4

“I've been absolutely terrified every moment of my life and I've never let it keep me from doing a single thing that I wanted to do.” ― Georgia O'Keefe


Look both ways


Important survey


What I want to accomplish today


Downloads

 


To do list


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

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

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



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

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

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



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



 


  🦆 © 2022 Jim Cohoon   Resources from previous semesters are available.