Class 07 – Wedneday, September 8

Make Bill Murray proud

Take another step — Chrestomathics awaits you — Feel the momentum

All Hoos got your back — A single community — In it together



Look both ways


Important survey


Not random thoughts


Agenda


My favorite complimenter.py interaction of all time

How old are you? 24

If aliens descended from space, they would classify you as 19



Downloads


To do list


Program temperature.py

f = 9/5 * c + 32

Enter Celsius temperature: 24

24 C = 75.2 F

24 C = 75 F

Enter Celsius temperature: 8

8 C = 46.4 F

8 C = 46 F



Program break_the_bank.py

ugly output

Number of quarters, dimes, nickels, and pennies: 27 14 28 18

Coinage

    27 quarters

    14 dimes

    28 nickels

    18 pennies

are worth 9.73 dollars

Number of quarters, dimes, nickels, and pennies: 1 2 3 4

Coinage

    1 quarters

    2 dimes

    3 nickels

    4 pennies

are worth 0.64 dollars



Program who_what_and_where.py

  • id( n ) identifies where in memory to find n
  • type( n ) supplies what type of value is n

Enter integer and decimal: 3 4.159

reply: 3 4.159 <class 'str'> 140400369925360

n: 3 <class 'int'> 9720640

x: 4.159 <class 'float'> 140400370194512

Enter integer and decimal: 8 8.88

reply: 8 8.88 <class 'str'> 139778356653296

n: 8 <class 'int'> 9720800

x: 8.88 <class 'float'> 139778356922448



Program the_old_switcheroo.py

reply = input( 'Enter two words: ' )

w1, w2 = reply.split()

print( )

print( 'w1 =', w1 )

print( 'w2 =', w2 )

print()

# swap the values of w1 and w2

w1 = w2

w2 = w1

# print results

print( 'After swapping' )

print()

print( 'w1 =', w1 )

print( 'w2 =', w2 )

Enter two words: wahoo wah

w1 = wahoo

w2 = wah

After swapping

w1 = wah

w2 = wah



Program wiped.py

Enter text: scraunched is just one syllable

string of interest: scraunched is just one syllable :

  stripped version: scraunched is just one syllable :



Program thats_a_moray.py

s: When an Eel Climbs a Ramp to Eat Squid From a Clamp, That’s a Moray

s.lower(): when an eel climbs a ramp to eat squid from a clamp, that’s a moray

s.upper(): WHEN AN EEL CLIMBS A RAMP TO EAT SQUID FROM A CLAMP, THAT’S A MORAY

s.capitalize(): When an eel climbs a ramp to eat squid from a clamp, that’s a moray



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

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




bill murray


Dean Martin singing thats amore