Class 6 – Monday, January 27

Fearlessly we march on — variables and strings

A sign for knowing — what the future asks of us — demands we act now

I say love is love — For aren't we all just people — Living as we're made


Look both ways


Agenda


Illumination


Examples


Enquiring minds want to know


Program who_what_and_where.py

Enter word: dabchick

Enter integer: 1112

Enter decimal: 3.14

w is <class 'str'> and is at 140055893338224 and when printed displays dabchick

si is <class 'str'> and is at 140055893314560 and when printed displays 1112

sd is <class 'str'> and is at 140055893314504 and when printed displays 3.14

i is <class 'int'> and is at 140056017208112 and when printed displays 1112

d is <class 'float'> and is at 140056017236280 and when printed displays 3.14

Enter word: hydroxyzine

Enter integer: 2020

Enter decimal: 1.27

w is <class 'str'> and is at 140664446974064 and when printed displays hydroxyzine

si is <class 'str'> and is at 140664446950400 and when printed displays 2020

sd is <class 'str'> and is at 140664446950344 and when printed displays 1.27

i is a <class 'int'> and is at 140664570843952 and when printed displays 2020

d is a <class 'float'> and is at 140664570872120 and when printed displays 1.27

Enter word: 1112

Enter integer: 1112

Enter decimal: 1112

w is <class 'str'> and is at 140565116193848 and when printed displays 1112

si is <class 'str'> and is at 140565116193904 and when printed displays 1112

sd is <class 'str'> and is at 140565116193792 and when printed displays 1112

i is <class 'int'> and is at 140565240087344 and when printed displays 1112

d is <class 'float'> and is at 140565240115512 and when printed displays 1112.0



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

Program output

### print strings

a = hatstall

b = a b

c = a b

d = aren't

e = a

b

### string lengths

len( a ) = 8

len( b ) = 4

len( c ) = 3

len( d ) = 6

len( e ) = 3


Program combine_and_multiply.py

Program output

### operator + performs concatenation

a = fire

b = fighter

a + b = firefighter

### * operator produces repeated concatenation

m = Wahoo-Wah!

n = 3

m * n = Wahoo-Wah!Wahoo-Wah!Wahoo-Wah!

n * m = Wahoo-Wah!Wahoo-Wah!Wahoo-Wah!



Program i_need_water.py

water = 'H' + 2 + '0'

print( water )

water = 'H' + str( 2 ) + 'O'

print( water )



Program lickety_strip_and_split.py

q = ' Look there is a Blibbering Humdinger '

### mis-attempted stripping

q = ' Look there is a Blibbering Humdinger '

### stripping

q = ' Look there is a Blibbering Humdinger '

s = 'Look there is a Blibbering Humdinger'

### splitting

f = 'bananas $0.69'

c = 'SEAS CS 1112'

bananas costs $0.69 per pound

School: SEAS subject: CS number: 1112

### list making

s1 = ['bananas', '$0.69']

s2 = ['SEAS', 'CS', '1112']



Program all_consuming.py — due Wednesday January 27

What is something you consume daily? paper napkins

How much consumed on a normal weekday: 6

How much consumed on a normal weekend day: 0

You consume 1560 paper napkins per year.

What is something you consume daily? pretzels

How much consumed on a normal weekday: 0

How much consumed on a normal weekend day: 1

You consume 104 pretzels per year.

What is something you consume daily? jelly beans

How much consumed on a normal weekday: 4

How much consumed on a normal weekend day: 12

You consume 2288 jelly beans per year.



To do list


image from wikimedia.org, magical mystery tour album cover

All you need is love — All you need is love — All you need is love, love — Love is all you need.     The Beatles

 


 
  © 2020 Jim Cohoon   Resources from previous semesters are available.