v is for
play

V is for Viral Video Husky Dog sings with iPAD 18 million views - PowerPoint PPT Presentation

V is for Viral Video Husky Dog sings with iPAD 18 million views https://www.youtube.com/watch?v=Mk4bmK-acEM Virtual Memory It is and is not there! Virtual Reality Augmenting IRL http://bit.ly/vr-playlist


  1. V is for … • Viral Video • Husky Dog sings with iPAD – 18 million views • https://www.youtube.com/watch?v=Mk4bmK-acEM • Virtual Memory • It is and is not there! • Virtual Reality • Augmenting IRL • http://bit.ly/vr-playlist 11/5/2020 Compsci 101, Fall 2020 2

  2. Announcements • APT APT-7 du due T Thur ursda day, N Nov 5 5, T TODAY! • APT APT-8 d due e Tues esday, N Nov 10 • Assign 6 n 6 Recommender, d due ue T Thur urs 1 11/12 • Assign 7 n 7 Create due ue, Monda nday, N Nov 1 16! • Final E Exam Su m Sunday, N Nov 2 22 – ta take o on th this day 11/5/2020 Compsci 101, Fall 2020 3

  3. PFTD • Colla laboration and C Creativ ivit ity • The power of working together with code • Revie iew m w module les a and e exceptio ions • Concepts used in Lab 9, leveraging creativity • How w to s solv lve it it • Thinking about steps 5-7, Python, and scale • Med edal alTabl able APT APT 11/5/2020 Compsci 101, Fall 2020 4

  4. The Power of Collaboration: Ge Wang, Duke Prof. at Stanford • Duk uke 2 2000: M Mus usic a and nd Computer S Science • https://www.stanforddaily.com/2016/03/09/qa-with-ge-wang- father-of-stanford-laptop-orchestra/ • http://www.youtube.com/watch?v=ADEHmkL3HBg • Abou out D Design i in Compsci ci 308 308 Our investment into a huge and meticulous design process was a huge factor in making later progress. 35000+ lines of code / design / documentation gave us a project we were all very happy and proud to be a part of. 11/5/2020 Compsci 101, Fall 2020 5

  5. Assignment 7: Create, Due Nov. 16 Grace period til Nov. 19, No late days! Must be turned in by Nov 19 This assignment is required! Pick o one ne: Video: : Green en d dance, advertisemen ement f for 101, s , song, o , other er Poem or oem or Multiple H e Hai aikus Sto tory Comi Comic One-pag ager er Feedback Let's s see s some e examples 11/5/2020 Compsci 101, Fall 2020 6

  6. Comic 11/5/2020 Compsci 101, Fall 2020 9

  7. Comic 11/5/2020 Compsci 101, Fall 2020 10

  8. Lab 9 Modules for Creating • “MadLibs” ” → Ta Tag-a-Sto tory • User chooses template • Computer fills everything in In lecture I saw a <color> <noun> For lunch I had a <adjective> <food> The day ended with seeing a <animal> <verb> in <place> 11/5/2020 Compsci 101, Fall 2020 11

  9. Main Parts for tag-a-story • Put e everything t together, t the template a and words • Storyline.py • Loadi ding ng and h d handl ndling ng u user choosing ng t templates • TemplateChooser.py • Loadi ding ng and p d picking ng t the word f for a a given n tag • Replacements.py 11/5/2020 Compsci 101, Fall 2020 12

  10. From <noun> to story In lecture I saw a In lecture I saw a <color> <noun> magenta house For lunch I had a For lunch I had a <adjective> <food> luminous hummus The day ended with The day ended with seeing a <animal> seeing a cow sleep <verb> in <place> in Mombasa This Photo by Unknown This Photo by Unknown Author is This Photo by Unknown Author is Author is licensed under CC licensed under CC BY-NC-ND licensed under CC BY-SA BY-NC-ND 11/5/2020 Compsci 101, Fall 2020 13

  11. Let's create/modify a story • Choose a a template o or make a a new one • We'll choose lecturetemplate.txt first • Add a a new category/replacement • We'll choose number and list some choices • Run the p program a and te test o our modification ons • Randomized, hard to test, but doable 11/5/2020 Compsci 101, Fall 2020 14

  12. Modules in Action makeStory in Storyline.py • How c can an we a acces ess TemplateChooser functi tion ons? • import and access as shown 11/5/2020 Compsci 101, Fall 2020 15

  13. Understanding Code/Module doWord in StoryLine.py • What d does get etRep eplac acemen ent do? ? • How does getReplacement do it? 11/5/2020 Compsci 101, Fall 2020 16

  14. The other module’s “what” • Get te t template • TemplateChooser.getTemplateLines(DIR) • What: • From the templates in the directory DIR (type: str) • Return a list of strings, where each element is a line from one of the templates in DIR • Wor ord f for or a a tag • Replacements.getReplacement(TAG) • What: • Return a random word that matches TAG (type: str) 11/5/2020 Compsci 101, Fall 2020 17

  15. Main Parts for tag-a-story • Put e everything t together, t the template a and words • Storyline.py • Loadi ding ng and h d handl ndling ng u user choosing ng t templates • TemplateChooser.py • Loadi ding ng and p d picking ng t the word f for a a given n tag • Replacements.py 11/5/2020 Compsci 101, Fall 2020 18

  16. TemplateChooser.py Steps • Lis ist a all t ll templates in in the fold lder • Get t user i input t that c t choos ooses o one • Load t that template • Return as l list of of strings 11/5/2020 Compsci 101, Fall 2020 19

  17. These Steps in Code getTemplateLines in TemplateChooser.py • Read d director ory o of te templates, c con onvert to to d dicti tion onary • Let user choose one, open and return it 11/5/2020 Compsci 101, Fall 2020 21

  18. Creating User Menu dirToDictionary in TemplateChooser.py • What d does this f function r return? W What t type? 11/5/2020 Compsci 101, Fall 2020 22

  19. pathlib Library • Pa Path: “rodger/Pycharm/cps101/lab09/temp/haiku.txt” • Th The e pathlib lib library is is more recent/ t/Pyth thon3 • Simpler, easier to use than functions from os • Handles d doma omain s speci cifics cs! • Doesn’t matter if on Windows, Mac, etc. • We worry about the what at , it handles the how ow 11/5/2020 Compsci 101, Fall 2020 23

  20. pathlib Library cont. • Pa Path: “rodger/Pycharm/cps101/lab09/temp/haiku.txt” • pathlib.Path(DIR).iterdir() • Returns iterable of Path objects representing each “thing” in the directory DIR • Path o object’s . s .parts s – tuple o of strings, eac each el elem emen ent i is a a pi piece of a fi filename’s pa s path • (‘rodger’, ‘Pycharm’, ‘cps101’,’lab09’, ‘temp’, ‘haiku.txt’) 11/5/2020 Compsci 101, Fall 2020 24

  21. Understanding the Unknown chooseOne in TemplateChooser.py • We w will r return t to this, bu but a analyze pa parts n now • What's familiar? What's not familiar … 11/5/2020 Compsci 101, Fall 2020 25

  22. Python exceptions • What s should you ou d do i o if you ou prom ompt user f for or a a num number and nd t the hey ent nter " "one" • Test to see if it has digits? • Us Use e exceptio ions wit with try: and except: • See code in function chooseOne from TemplateChooser.py 11/5/2020 Compsci 101, Fall 2020 26

  23. Handling Exceptions • What h happe pens: x = int("123abc") 11/5/2020 Compsci 101, Fall 2020 27

  24. WOTO-1 Modules http://bit.ly/101f20-1105-1 11/5/2020 Compsci 101, Fall 2020 28

  25. Christos Papadimitriou • Gödel el p prize f for c concep ept o of "price o e of anar archy" y" I would say that, quite generally, computer scientists are going to find themselves interacting more with other fields. I encourage my students to go completely wild in their curriculum, to go out and learn not only that which they think they should learn in order to be good computer scientists—usually mathematics and programming and engineering and so on— but learn about everything else, about psychology, economics, about business, about biology, about the humanities. (2008) 11/5/2020 Compsci 101, Fall 2020 29

  26. When and What’s in CompSci 101 • Problem t to s o sol olve • Use 7 steps • Step 5: How do you translate algorithm to code? • What do you use to solve it? • When do you use it? 11/5/2020 Compsci 101, Fall 2020 30

  27. What are the “what’s”? • Data ta Structures: list, t, s set, d dicti tion onary, tu tuple • Loops a and nd iterables: f from om for or t to o while t to o it iterdir ir() () • Other er: • List comprehensions • Parallel lists • Lambda • If…if…if • If…elif…else 11/5/2020 Compsci 101, Fall 2020 31

  28. Quick When’s and What’s for 101 • Whichever m makes es m more s e sense e to you: • Parallel lists vs dictionaries • If…if…if vs if…elif…else • List comprehension vs for loop • Tuples vs Lists • If you want to prevent mutation -> tuples • Need single line function • Lambda vs create normal helper function 11/5/2020 Compsci 101, Fall 2020 32

  29. APT – Sorted Freqs 11/5/2020 Compsci 101, Fall 2020 33

  30. What's the best way to … • Sorted edFreq eqs https://www2.cs.duke.edu/csed/pythonapt/sortedfreqs.html • • Count unt how m many ny t times each s string ng o occur urs • Create d = {}, iterate over list updating values • Use data.count(w) for each w • Wait, that looks like … 11/5/2020 Compsci 101, Fall 2020 34

  31. APT: SortByFreqs 11/5/2020 Compsci 101, Fall 2020 36

  32. Wait, wait, but what's … • SortByFreqs https://www2.cs.duke.edu/csed/pythonapt/sortbyfreqs.html • • Sort b by # # occurren ences h high t to l low • Tuples with count/lambda and reverse=True? • Break ties in alphabetical order: two passes 11/5/2020 Compsci 101, Fall 2020 37

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend