Class 12 – Monday, March 1

Tabling

An optimist thinks — Elevator close button — Really does something


Look both ways


Agenda


Downloads

 


To do list


Datasets


Program c_looper.py

row : 0 1 2 ... n-1

Enter number of columns: 5

row : 0 1 2 3 4


Enter number of columns: 12

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



Program going_rowing.py

table: [['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I'], ['J', 'K', 'L', 'M']]

the table has 4 rows

row ['A', 'B', 'C'] has 3 columns

row ['D', 'E', 'F'] has 3 columns

row ['G', 'H', 'I'] has 3 columns

row ['J', 'K', 'L', 'M'] has 4 columns

row 0 : ['A', 'B', 'C']

row 1 : ['D', 'E', 'F']

row 2 : ['G', 'H', 'I']

row 3 : ['J', 'K', 'L', 'M']



Program rc_printing.py

Number of rows and columns: 3 4

0 1 2 3

1 2 3 4

2 3 4 5

Number of rows and columns: 4 5

0 1 2 3 4

1 2 3 4 5

2 3 4 5 6

3 4 5 6 7



Program rc_making.py

Number of rows and columns: 3 4

row 0

[0, 1, 2, 3]

row 1

[1, 2, 3, 4]

row 2

[2, 3, 4, 5]

table = [[0, 1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5]]

Number of rows and columns: 2 5

row 0

[0, 1, 2, 3, 4]

row 1

[1, 2, 3, 4, 5]

table = [[0, 1, 2, 3, 4], [1, 2, 3, 4, 5]]



Program column_grabbing.py

table = [['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I'], ['J', 'K', 'L', 'M']]

Enter column of interest: 0

row ['A', 'B', 'C'] : column 0 cell: A

row ['D', 'E', 'F'] : column 0 cell: D

row ['G', 'H', 'I'] : column 0 cell: G

row ['J', 'K', 'L', 'M'] : column 0 cell: J

Column 0 : ['A', 'D', 'G', 'J']

table = [['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I'], ['J', 'K', 'L', 'M']]

Enter column of interest: 2

row ['A', 'B', 'C'] : column 2 cell: C

row ['D', 'E', 'F'] : column 2 cell: F

row ['G', 'H', 'I'] : column 2 cell: I

row ['J', 'K', 'L', 'M'] : column 2 cell: L

Column 2 : ['C', 'F', 'I', 'L']



Web pages

Our introduction to interacting with the web in CS 1112 is intentionally simple. Industrial-strength web applications also require familiarity with other and more powerful URL modules. There is an external library requests worth checking if you have further interest.

For now the only thing we is access to the module urllib.request. The module supports working with URLs.

import urllib.request

stream = urllib.request.urlopen( link )

page = stream.read()

text = page.decode( 'UTF-8' )

The above assignment sets text to be the decoded contents of the url resource named by link; that is text is a string equally the contents of the url resource indicted by ;ink.

import urllib.request # get module access

stream = urllib.request.urlopen( link ) # open connector to the link web resource

page = stream.read() # read contents of the resource

text = page.decode( 'UTF-8' ) # decode contents as normal text string


Program master_plan.py

???



author: Dmarcus100; periodic table of elements Wikimedia Commons

 


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