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
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Compsc psci 101 101 Turtle, B Bagels, s, L Loop T p Tracing ng, F Files Liv ive L Lec ecture

9/15/2020 Compsci 101, Fall 2020 1

Susan Rodger September 15, 2020

slide-2
SLIDE 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

  • ut tod
  • day – due 9

9/22 22

  • Assignment 2

t 2 Turtl tles o

  • ut

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

slide-3
SLIDE 3

Exam 1 Studying

  • Exam

am 1 1 is Sep Sept 24, 24, nex ext Th Thursday

  • Cove

vers top

  • pics

cs th through th this is w week

  • Not while loops, not files
  • How
  • w 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

slide-4
SLIDE 4

APT Quiz 1

  • APT Quiz 1

1 is 9/ 9/25 25-9/28 28 ( (no l lab o

  • n 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

  • sol
  • lve
  • 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

slide-5
SLIDE 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

slide-6
SLIDE 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

slide-7
SLIDE 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

slide-8
SLIDE 8

WOTO-2: Let’s draw it 3 times!

  • TPS: W

What will t will the t turtle d dra raw?

  • Note: Think about where the turtle is and facing

after each iteration

9/15/2020 Compsci 101, Fall 2020 8

Option 1 (Draw 3 triangles on top of each

  • ther)

Option 2 Option 3 Option 4

Orientation and location matters!

slide-9
SLIDE 9

Bagels (Accumulation)

9/15/2020 Compsci 101, Fall 2020 9

This Photo by Unknown Author is licensed under CC BY-NC-ND

slide-10
SLIDE 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

slide-11
SLIDE 11

9/15/2020 Compsci 101, Fall 2020 11

slide-12
SLIDE 12

Examples

9/15/2020 Compsci 101, Fall 2020 12

slide-13
SLIDE 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

slide-14
SLIDE 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

slide-15
SLIDE 15

WOTO-3 Step 3: Generalize http://bit.ly/101f20-0915-3

9/15/2020 Compsci 101, Fall 2020 15

slide-16
SLIDE 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

  • r 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

slide-17
SLIDE 17

Step 4: Test steps

  • Go through list
  • If less than 12
  • Do nothing
  • If greater than or equal

to 12

  • Add however many times

12 goes into the order

  • Sum everything
  • [11, 22, 33, 44, 55]
  • 11
  • Nothing (less than 12)
  • 22
  • +1
  • 33
  • +2
  • 44
  • +3
  • 55
  • +4
  • Sum: 175

9/15/2020 Compsci 101, Fall 2020 17

slide-18
SLIDE 18

Step 5: Code

  • Go through list
  • If less than 12
  • Do nothing
  • If greater than or equal

to 12

  • Add however many

times 12 goes into the

  • rder
  • Sum everything
  • for loop!
  • if statement
  • TPS: if’s or if…else

statement?

  • floor div: //

9/15/2020 Compsci 101, Fall 2020 18

Could we use the accumulator pattern? Yes!

slide-19
SLIDE 19

Step 5: Code

9/15/2020 Compsci 101, Fall 2020 19

Initialize before loop Update inside loop Do something with value after loop

slide-20
SLIDE 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

slide-21
SLIDE 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

  • f 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

slide-22
SLIDE 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

  • n o
  • f the loop
  • In y

your g groups ps:

  • Come to a consensus

9/17/2020 Compsci 101, Fall 2020 22