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 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 out 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
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
Review: List Comprehension Syntax ret = [] for V in LIST: ret = [V_EXP for V in LIST] ret.append(V_EXP) ret = [] for V in LIST: if BOOL_EXP: ret.append(V_EXP) ret = [V_EXP for V in LIST if BOOL_EXP] • 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 often en u use e V 9/29/20 Compsci 101, Fall 2020 4
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
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
Keith Kirkland https ://tw itter .com/ cstea chers org/s tatus /1229 36020 66201 02656 9/29/20 Compsci 101, Fall 2020 9
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
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
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! Look at code 9/29/20 Compsci 101, Fall 2020 12
Reminder: Global Variables (Best Practice) • Best p prac actice = = hel elp o other 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 of the he f func nction 9/29/20 Compsci 101, Fall 2020 13
Reminder: What, where, read, write? (in 101) Where first Where accessible? Where reassign- What is it? created? (read) able? (write) Regular variable In main In main only In main only in main (technically anywhere, but don’t do that) Regular local In function In function only In function only function variable Global variable Top of file If not reassigning the In main or in any value, in main and all function that first functions declares it global 9/29/20 Compsci 101, Fall 2020 14
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
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 o to C o Con onsulting hours rs • What happens when you run Transform? 9/29/20 Compsci 101, Fall 2020 16
Recommend
More recommend