Class 21 — Monday March 14

Introduction to "while"

This is the beginning of anyting you want

Look both ways


Joke of the day

shampoo noun project #:4235548

Agenda


To do


Examples


Problem arrangements.py

  • The start value is m; the stop value is less than n; and the other values go up in steps of k
  • The start value is m; the stop value is greater than n; and the other values go down in steps of k

Enter integers m, n, and k: 3 8 2

i: 3

i: 5

i: 7

list( range( m, n, k ) ): [3, 5, 7]

Enter integers m, n, and k: 10 6 -3

i: 10

i: 7

list( range( m, n, k ) ): [10, 7]



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

while ( test expression ) :

  action

else :

  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 )



Problem yes_or_no.py


Problem guess_what.py



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

Agenda


To do


Examples


Some data sets


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 association with 'potato' is now only 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

Where am I

jpc @ love is love

 


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