Compsc psci 101 101 List st C Compr prehe hens nsions, ns, T - - PowerPoint PPT Presentation

compsc psci 101 101 list st c compr prehe hens nsions ns
SMART_READER_LITE
LIVE PREVIEW

Compsc psci 101 101 List st C Compr prehe hens nsions, ns, T - - PowerPoint PPT Presentation

Compsc psci 101 101 List st C Compr prehe hens nsions, ns, T Transf nsform, Global al - Live L e Lec ecture Susan Rodger September 29, 2020 9/29/20 Compsci 101, Fall 2020 1 Announcements Assign ign 2 2 Turtl tles d


slide-1
SLIDE 1

Compsc psci 101 101 List st C Compr prehe hens nsions, ns, T Transf nsform, Global al - Live L e Lec ecture

9/29/20 Compsci 101, Fall 2020 1

Susan Rodger September 29, 2020

slide-2
SLIDE 2

Announcements

  • Assign

ign 2 2 – Turtl tles d due to tonight! t!

  • APT

APT-4 4 out t to today d due T Tuesday, O Oct 6 t 6

  • Assign

ign3-Tra ransform rm ou

  • ut today,

y, du due Thur ursda day, O Oct 8 8

  • There is a Sakai quiz on Assign3 – also by Oct 8
  • Ex

Exam 1 1 – do no not d discuss with a any nyone unt until ha handed bac ack

  • It is not autograded! Be patient!

9/29/20 Compsci 101, Fall 2020 2

slide-3
SLIDE 3

PFTD

  • List C

Comprehe hens nsions ns

  • Global V

l Varia iable les

  • Transform A

m Assignme ment

9/29/20 Compsci 101, Fall 2020 3

slide-4
SLIDE 4

Review: List Comprehension Syntax

  • V is

is any v variable: a all lis ll list e ele lements in in order

  • V_EXP is any

y expr pres ession, o

  • ften

en u use e V

9/29/20 Compsci 101, Fall 2020 4

ret = [] for V in LIST: ret.append(V_EXP) ret = [V_EXP for V in LIST] ret = [] for V in LIST: if BOOL_EXP: ret.append(V_EXP) ret = [V_EXP for V in LIST if BOOL_EXP]

slide-5
SLIDE 5

WOTO-1 List Comprehension Examples http://bit.ly/101f20-0929-1

  • In y

your g groups ps

  • Come to a consensus

9/29/20 Compsci 101, Fall 2020 5

slide-6
SLIDE 6

WOTO-2 List Comprehension Examples http://bit.ly/101f20-0929-2

  • In y

your g groups ps

  • Come to a consensus

9/29/20 Compsci 101, Fall 2020 7

slide-7
SLIDE 7

Keith Kirkland

9/29/20 Compsci 101, Fall 2020 9 https ://tw itter .com/ cstea chers

  • rg/s

tatus /1229 36020 66201 02656

slide-8
SLIDE 8

Assignment 3: Transform

  • Reading

ng a and nd w writing ng files

  • We've seen how to read, writing is similar
  • Open, read, and close
  • Open, write, and close - .write(…)
  • Apply

y a f function to e ever ery y word d in a a f file

  • Encrypt and decrypt
  • Respect lines, so resulting file has same

structure

9/29/20 Compsci 101, Fall 2020 10

slide-9
SLIDE 9

Encrypting and Decrypting

  • We g

give y you:

  • Transform.py
  • Vowelizer.py - Removes vowels
  • You im

imple lement

  • Pig Latin
  • Caesar cipher
  • Ch

Challe llenge: Shuffleizer

9/29/20 Compsci 101, Fall 2020 11

slide-10
SLIDE 10

Concepts in Starter Code

  • Global v

l variable les

  • Generally avoided, but very useful
  • Accessible in all module functions
  • File

ileDialo log and tkinte ter

  • API and libraries for building UI and UX
  • Docstri

rings gs for u understandi ding!

9/29/20 Compsci 101, Fall 2020 12

Look at code

slide-11
SLIDE 11

Reminder: Global Variables (Best Practice)

  • Best p

prac actice = = hel elp o

  • ther

er h humans read ad t the c e code

  • All

ll variables that will will be glo lobal are c created wit with a an initial al as assignmen ent at at t the t e top of the f e file

  • When

en used ed in a a f function, va variab able e is d dec eclar ared d globa bal a at t the beginni nning ng o

  • f the

he f func nction

9/29/20 Compsci 101, Fall 2020 13

slide-12
SLIDE 12

Reminder: What, where, read, write? (in 101)

What is it? Where first created? Where accessible? (read) Where reassign- able? (write) Regular variable in main In main In main only (technically anywhere, but don’t do that) In main only Regular local function variable In function In function only In function only Global variable Top of file If not reassigning the value, in main and all functions In main or in any function that first declares it global

9/29/20 Compsci 101, Fall 2020 14

slide-13
SLIDE 13

WOTO-3 – Globals http://bit.ly/101f20-0929-3

  • If you a

are d e done e early, revi vise a e and c d collab aborate e on your n note tes!

  • In

In your g groups ps:

  • Come to a consensus

9/29/20 Compsci 101, Fall 2020 15

slide-14
SLIDE 14

Tkinter and FileDialog

  • This

is lib library a and A API is is useful l for c r creating G GUI UIs

  • Difficult and not always about the big picture
  • Debugging can be frustrating
  • Tedium of making things right versus exultation

in creating wonderful programs!

  • If you d

don't 't s see t e the r e rocket-shi hip? Go t

  • to C
  • Con
  • nsulting

hours rs

  • What happens when you run Transform?

9/29/20 Compsci 101, Fall 2020 16