Class 21 – Wednesday October 16

You are so controlling

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


Look both ways


Agenda


To do


Downloads


Maxims (among others)


To be considered

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

  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


Program guess_what.py


Program romantic.py

Three sample program runs

Enter Roman numeral: V

5

Enter Roman numeral: d

500

Enter Roman numeral: 0

Unknown



Program unromantic.py

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


Program even_odd.py

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



Program good_doggie.py

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

  • Sequential
  • Nested
  • Mixture of nested and sequential

Huh?


Program que_dijiste.py

{'aab': 'water', 'aamadam': 'came', 'aamadand': 'came', 'aamad': 'came', 'aamadi': 'came',

...

'wollen': 'want', 'wort': 'word', 'wo': 'where', 'y': 'and', 'yo': 'I', 'Yo': 'I', 'yun': 'wool', 'yün': 'wool', 'zahl': 'number', 'zauberformel': 'spell', 'zauberhaft': 'enchanting', 'zehn': 'ten', 'zeichen': 'characters', 'zeigt': 'show', 'ziba': 'beautiful', 'zur': 'to', 'zu': 'to', 'zwei': 'two', '是': 'is', '该': 'the'}

Next class — what we really want to do

Enter phrase to be translated: dónde está mi lápiz

where is my pencil

Enter phrase to be translated: est la baguette fraîche aujourd'

is the baguatte fresh today

Enter phrase to be translated: je %#@#&# ból svayam!!

I >%#@#&#< hurt myself >!!<

Enter phrase to be translated: hvor er den skriget maleri af Munch

where is the scream painting by Münch

Enter phrase to be translated: hacer 뭔가 frais oggi

do something cool today

  • How should we store the translations?
  • How should we store the input?
  • How should we store the result?
  • What times of loops do we need?


raining cats and dogs

 


 

 

 
   
   
   
 
  © 2019 Jim Cohoon   Resources from previous semesters are available.