Class 11 – Friday, February 7

Building and examining lists

An optimist thinks — Elevator close button — Really does something


Look both ways


Agenda


Peer mentoring


Downloads


To do list


Chrestomathics — program secret_decoder.py

Scenario

'abcdefghijklmnopqrstuvwxyz-'

and the indices are

[ 4, 8, 26, 4, 8, 26, 14 ]

Mandatory algorithm

# get the code phrase that contains hidden message

# clean up reply to get code phrase with no leading or trailing whitespace

# print the code phrase

# get the list of indices (as string) for peeking into code phrase

# convert reply into a list of numeric strings

# build one-by-one the list of indices out of the numeric strings

# print the list of indices

# build secret message (string) by peeking into code phrase using the indices

# print secret message

Some program runs

Enter code phrase: computer

Code phrase: computer

Enter indices: 3 6 5

Indices: [3, 6, 5]

Hidden message: pet

Enter code phrase: gosh look what the cat is up to now

Code phrasee: gosh look what the cat is up to now

Enter indices: 24 5 17 17 27 23 32 0

Indices: [24, 5, 17, 17, 27, 23, 32, 0]

Hidden message: sleeping

Enter code phrase: ‐abcdefghijklmnopqrstuvwxyz‐

Code phrase: ‐abcdefghijklmnopqrstuvwxyz-

Enter indices: 12 15 22 5 27 9 19 0 1 12 12 27 14 5 5 4

Indices: [12, 15, 22, 5, 27, 9, 19, 0, 1, 12, 12, 27, 14, 5, 5, 4]

Hidden message: love‐is‐all‐need



Program thats_printastic.py — introduce optional closing parameter end="..."

A program run

Wa‐Hoo‐Wa

Rah‐Rah‐Rah

Wa‐Hoo‐Wa!!!Rah‐Rah‐Rah

Wa‐Hoo‐Wa !!! Rah‐Rah‐Rah

t‐a‐t‐t‐a‐r‐r‐a‐t‐t‐a‐t-

saippuakivikauppias



Program i_looper.py

i: 0 1 2 ... i



Nested looping — program nested_looper.py

i: 0 1 2 ... i

Two possible program runs

Enter number: 5

0: 0

1: 0 1

2: 0 1 2

3: 0 1 2 3

4: 0 1 2 3 4

Enter number: 12

0: 0

1: 0 1

2: 0 1 2

3: 0 1 2 3

4: 0 1 2 3 4

5: 0 1 2 3 4 5

6: 0 1 2 3 4 5 6

7: 0 1 2 3 4 5 6 7

8: 0 1 2 3 4 5 6 7 8

9: 0 1 2 3 4 5 6 7 8 9

10: 0 1 2 3 4 5 6 7 8 9 10

11: 0 1 2 3 4 5 6 7 8 9 10 11




Tiger and Turtle Magic Mountain

 


 
  © 2020 Jim Cohoon   Resources from previous semesters are available.