Class 06 – Monday, September 5

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 are


Look both ways


Agenda


Examples


Program iiiii.py

# define an iterator variable named i, and initialize it to 0

i = 0

   

print( "i:", i )

print()

   

# increment i by one (for the first time)

i = i + 1 # i's new value is its current value plus 1

   

print( "i:", i )

print()

   

# increment i by one (for a second time)

i = i + 1 # i's new value is its current value plus 1

   

print( "i:", i )

print()

   

# increment i by one (for a third time)

i = i + 1 # i's new value is its current value plus 1

   

print( "i:", i )

print()

   

# increment i by one (for a fourth time)

i = i + 1 # i's new value is its current value plus 1

   

print( "i:", i )

print()

   

# increment i by one (for a fifth time)

i = i + 1 # i's new value is its current value plus 1

   

print( "i:", i )

print()



Program being_powerful.py

  • Get inputs
  • Massage inputs into needed values
  • Compute result
  • Print result

Enter base (integer): 2

Enter exponent (decimal): 0.5

1.4142235623730951

Enter base (integer): 11

Enter exponent (decimal): 3.14

1861.971509290233

Enter base (integer): 4

Enter exponent (decimal): 0.333

1.5866676863822857



Program trio.py

Enter three words: peace joy friends

Your words

peace

joy

friends

Enter three words: ready or not

Your words

ready

or

not



Program i_get_around.py

Enter number: 3.1415926

number: 3.1415926

round( number ): 3

round( number, 6 ): 3.141593

round( number, 5 ): 3.14159

round( number, 4 ): 3.1416

round( number, 3 ): 3.142

round( number, 2 ): 3.14

round( number, 1 ): 3.1

round( number, 0 ): 3.0

Enter number: 2.7182818

number: 2.7182818

round( number ): 3

round( number, 6 ): 2.718282

round( number, 5 ): 2.71828

round( number, 4 ): 2.7183

round( number, 3 ): 2.718

round( number, 2 ): 2.72

round( number, 1 ): 2.7

round( number, 0 ): 3.0



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


Assumptions


Requirements


Suggested agorithm


Three program runs

What is something you consume daily? paper napkins

How much consumed on a typical weekday: 6

How much consumed on a typical weekend day: 0

You consume 1560 paper napkins per year.

What is something you consume daily? pretzels

How much consumed on a typical weekday: 0

How much consumed on a typical weekend day: 1

You consume 104 pretzels per year.

What is something you consume daily? jelly beans

How much consumed on a typical weekday: 4

How much consumed on a typical 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