Class 22 — Wednesday March 4

You are so controlling

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


Look both ways


Agenda


Please take care

handwashing - for rights see https://openphoto.net/gallery/image/view/20391

To do


Redownload


Examples


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


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

Huh?


Problem 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?



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.