Class 21 — Monday October 12

You are so controlling

While I can go on – I do not repeat myself – Always a new way


Look both ways


Agenda


To do


Redownload


Examples


Maxims (among others)


For your consideration

Enter (yes / no): YES

yes

Enter (yes / no): No

no

Enter (yes / no): yeah

Enter (yes / no): yeap

Enter (yes / no): tá

Enter (yes / no): כן

Enter (yes / no): ndiyo

Enter (yes / no): haan

Enter (yes / no): YeS

yes

Enter (yes / no): nah

Enter (yes / no): không

Enter (yes / no): nope

Enter (yes / no): aʻole

Enter (yes / no): ei

Enter (yes / no): NO

no



Whiling away

while ( test expression ) :

  action

looking_for_a_yes_or_no = True

while ( looking_for_a_yes_or_no == True ) :

  reply = input( 'Enter (yes / no): ' )

  reply = reply.lower()

  if ( reply in [ 'yes', 'no' ] ) :

  looking_for_a_yes_or_no = False

print( reply )

while ( test expression ) :

  action

else :

  action



Problem guess_what.py


Problem romantic.py

Some program runs

Enter Roman numeral: V

5

Enter Roman numeral: d

500

Enter Roman numeral: 0

Unknown



Problem unromantic.py

Some program runs

RecursionError: maximum recursion depth exceeded during compilation



Discussion

flora_to_color = { 'spruce': 'green', 'apple': 'red', 'shamrock': 'green',

  'banana': 'yellow', 'potato': 'brown', 'eggplant': 'purple' }

flora_to_color[ 'lemon' ] = 'yellow'

flora_to_color[ 'potato' ] = 'golden'

would cause flora_to_color to lose its association of mapping potato to brown — its only associaton with 'potato' is to golden.

the_keys = flora_to_color.keys()

the_values = flora_to_color.values()

While there are never any duplicates in the keys, depending upon the dictionary there may be duplicates in the values.


Problem even_odd.py

Some program runs

Enter a number: 3

3 odd

Enter even or odd: even

a number is even if its remainder divided by 2 is 0

Enter a number: 6

6 even

Enter even or odd: odd

a number is odd if its remainder divided by 2 is 1



Problem good_doggie.py

http://www.cs.virginia.edu/~cs1112/datasets/csv/puppies.csv

  • Sequential
  • Nested
  • Mixture of nested and sequential

brainstorming - for rights see https://www.flickr.com/photos/99537327@N02/9472941659


raining cats and dogs

 


  © 2020 Jim Cohoon   Resources from previous semesters are available.