compsc psci 101 101 turtle b bagels s l loop t p tracing
play

Compsc psci 101 101 Turtle, B Bagels, s, L Loop T p Tracing - PowerPoint PPT Presentation

Compsc psci 101 101 Turtle, B Bagels, s, L Loop T p Tracing ng, F Files Liv ive L Lec ecture Susan Rodger September 15, 2020 9/15/2020 Compsci 101, Fall 2020 1 Announcements APT APT-2 du due toni night! Remember you get


  1. Compsc psci 101 101 Turtle, B Bagels, s, L Loop T p Tracing ng, F Files Liv ive L Lec ecture Susan Rodger September 15, 2020 9/15/2020 Compsci 101, Fall 2020 1

  2. Announcements • APT APT-2 du due toni night! • Remember you get 24-hour grace period, can’t turn in after that! • APT APT-3 ou out tod oday – due 9 9/22 22 • Assignment 2 t 2 Turtl tles o out t – due due 9 9/29 • Lab 4 b 4 Friday – has pr prelab t to do do be before l lab! b! 9/15/2020 Compsci 101, Fall 2020 2

  3. Exam 1 Studying • Exam am 1 1 is Sep Sept 24, 24, nex ext Th Thursday • Cove vers top opics cs th through th this is w week • Not while loops, not files • How ow to to stu tudy • Write code on paper or type code in a plain text file • Redo code you have already done, we did class • Try things in Python Tutor, in Python Console • Review all notes • Old tests on Resources tab • Spring 18 on, is Python 3, Before that Python 2 • Try timing yourself on old exams? • CS101 Reviewer APP – use in prelab for Lab 4 9/15/2020 Compsci 101, Fall 2020 3

  4. APT Quiz 1 • APT Quiz 1 1 is 9/ 9/25 25-9/28 28 ( (no l lab o on 9 9/25) 5) • Open en around und 8 8am 9 9/25 • Pic ick y your r start t tim ime, • Once you start, You have 2.5 hours • If you get accommodations, you get those • 3 APTs t to o sol olve • Will put ut up up p problems f from a an n old APT APT Q Qui uiz s so y you u can an p prac actice 9/15/2020 Compsci 101, Fall 2020 4

  5. WOTO-1 – Turtles Simple http://bit.ly/101f20-0915-1 • 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 y your g groups ps: • Come to a consensus 9/15/2020 Compsci 101, Fall 2020 5

  6. WOTO-2: Let’s draw a triangle! http://bit.ly/101f20-0915-2 • Equila lateral t l triangle le • Corner degrees: 60 • Side length: 100 9/15/2020 Compsci 101, Fall 2020 6

  7. WOTO-2: Let’s draw a triangle! http://bit.ly/101f20-0915-2 • Equila lateral t l triangle le • Corner degrees: 60 • Side length: 100 9/15/2020 Compsci 101, Fall 2020 7

  8. WOTO-2: Let’s draw it 3 times! Orientation and • TPS: W What will t will the t turtle d dra raw? location matters! • Note: Think about where the turtle is and facing after each iteration Option 3 Option 1 Option 2 (Draw 3 Option 4 triangles on top of each other) 9/15/2020 Compsci 101, Fall 2020 8

  9. Bagels (Accumulation) 9/15/2020 Compsci 101, Fall 2020 9 This Photo by Unknown Author is licensed under CC BY-NC-ND

  10. APT Bagels • How figure e out h how many b y bag agel els n need eeded? d? • 7-steps! 9/15/2020 Compsci 101, Fall 2020 10

  11. 9/15/2020 Compsci 101, Fall 2020 11

  12. Examples 9/15/2020 Compsci 101, Fall 2020 12

  13. Step 1 and 2 • Step ep 1 1: S Solve e an i instan ance (t (think) • orders = [11, 3, 24, 17] 9/15/2020 Compsci 101, Fall 2020 13

  14. Step 1 and 2 • Step ep 1 1: S Solve e an i instan ance ( (TPS) • orders = [11, 3, 24, 17] • Total: 58 • Step 2 2: W What di did w d we do do? • 11 + 3 + (24+2) + (17+1) = 58 9/15/2020 Compsci 101, Fall 2020 14

  15. WOTO-3 Step 3: Generalize http://bit.ly/101f20-0915-3 9/15/2020 Compsci 101, Fall 2020 15

  16. WOTO-3 Step 3: Generalize • Go t throug ugh l h list • If f less th than 12 12 • Do nothing • If grea eater er t than an o or equal al t to 12 • Add however many times 12 goes into the order • Sum e everything 9/15/2020 Compsci 101, Fall 2020 16

  17. Step 4: Test steps • Go through list • [11, 22, 33, 44, 55] • If less than 12 • 11 • Do nothing • Nothing (less than 12) • If greater than or equal • 22 to 12 • +1 • Add however many times • 33 12 goes into the order • +2 • Sum everything • 44 • +3 • 55 • +4 • Sum: 175 9/15/2020 Compsci 101, Fall 2020 17

  18. Step 5: Code • Go through list • for loop! • If less than 12 • if statement • Do nothing • If greater than or equal • TPS: if’s or if…else to 12 statement? • Add however many • floor div: // times 12 goes into the Could we use order the accumulator Yes! • Sum everything pattern? 9/15/2020 Compsci 101, Fall 2020 18

  19. Step 5: Code Initialize before loop Update inside loop Do something with value after loop 9/15/2020 Compsci 101, Fall 2020 19

  20. Donald Knuth • Until recently … • Was "The Donald" • Turing, Hopper, more … • Author of many works Art of Computer Programming Mad Magazine when 19 (author of TeX) “I can’t go to a restaurant and order food because I keep looking at the fonts on the menu.” 9/15/2020 Compsci 101, Fall 2020 20

  21. Code-Tracing a Loop 1. 1. Find d the c e chan anging va variab ables es/expressions 2. 2. Crea eate t table, columns a are va e variab ables/ex expres essions 1. First column is loop variable 2. Add columns to help track everything else 3. 3. Each r row is w is an it iteratio ion o of the lo loop 1. Before execute code block, copy down each variable’s value 2. Execute code block, update a value in the row as it changes 9/17/2020 Compsci 101, Fall 2020 21

  22. WOTO Loop Tracing http://bit.ly/101f20-0915-4 • Remem ember t the e steps eps ( (1) F Find t the e chan anging va variab able/expressions, ( (2) C Crea eate t the t e tab able w e with thes ese as as t the e column, and ( (3) E Eac ach row is a an ite terati tion on o of the loop • In y your g groups ps: • Come to a consensus 9/17/2020 Compsci 101, Fall 2020 22

Recommend


More recommend