Function Examples Announcements Hog Contest Rules 3 - - PowerPoint PPT Presentation

function examples announcements hog contest rules
SMART_READER_LITE
LIVE PREVIEW

Function Examples Announcements Hog Contest Rules 3 - - PowerPoint PPT Presentation

Function Examples Announcements Hog Contest Rules 3 cs61a.org/proj/hog_contest Hog Contest Rules Up to two people submit one entry; Max of one entry per person 3 cs61a.org/proj/hog_contest Hog Contest Rules Up to two people submit


slide-1
SLIDE 1

Function Examples

slide-2
SLIDE 2

Announcements

slide-3
SLIDE 3

Hog Contest Rules

3

cs61a.org/proj/hog_contest

slide-4
SLIDE 4

Hog Contest Rules

  • Up to two people submit one entry;

Max of one entry per person

3

cs61a.org/proj/hog_contest

slide-5
SLIDE 5

Hog Contest Rules

  • Up to two people submit one entry;

Max of one entry per person

  • Your score is the number of entries

against which you win more than 50.00001% of the time

3

cs61a.org/proj/hog_contest

slide-6
SLIDE 6

Hog Contest Rules

  • Up to two people submit one entry;

Max of one entry per person

  • Your score is the number of entries

against which you win more than 50.00001% of the time

  • Strategies are time-limited

3

cs61a.org/proj/hog_contest

slide-7
SLIDE 7

Hog Contest Rules

  • Up to two people submit one entry;

Max of one entry per person

  • Your score is the number of entries

against which you win more than 50.00001% of the time

  • Strategies are time-limited
  • All strategies must be deterministic,

pure functions of the players' scores

3

cs61a.org/proj/hog_contest

slide-8
SLIDE 8

Hog Contest Rules

  • Up to two people submit one entry;

Max of one entry per person

  • Your score is the number of entries

against which you win more than 50.00001% of the time

  • Strategies are time-limited
  • All strategies must be deterministic,

pure functions of the players' scores

  • Winning entries will receive a paltry

amount of extra credit

3

cs61a.org/proj/hog_contest

slide-9
SLIDE 9

Hog Contest Rules

  • Up to two people submit one entry;

Max of one entry per person

  • Your score is the number of entries

against which you win more than 50.00001% of the time

  • Strategies are time-limited
  • All strategies must be deterministic,

pure functions of the players' scores

  • Winning entries will receive a paltry

amount of extra credit

  • The real prize: honor and glory

3

cs61a.org/proj/hog_contest

slide-10
SLIDE 10

Hog Contest Rules

  • Up to two people submit one entry;

Max of one entry per person

  • Your score is the number of entries

against which you win more than 50.00001% of the time

  • Strategies are time-limited
  • All strategies must be deterministic,

pure functions of the players' scores

  • Winning entries will receive a paltry

amount of extra credit

  • The real prize: honor and glory
  • See website for detailed rules

3

cs61a.org/proj/hog_contest

slide-11
SLIDE 11

Hog Contest Rules

  • Up to two people submit one entry;

Max of one entry per person

  • Your score is the number of entries

against which you win more than 50.00001% of the time

  • Strategies are time-limited
  • All strategies must be deterministic,

pure functions of the players' scores

  • Winning entries will receive a paltry

amount of extra credit

  • The real prize: honor and glory
  • See website for detailed rules

3

cs61a.org/proj/hog_contest Kaylee Mann Yan Duan & Ziming Li Brian Prike & Zhenghao Qian Parker Schuh & Robert Chatham Fall 2011 Winners

slide-12
SLIDE 12

Hog Contest Rules

  • Up to two people submit one entry;

Max of one entry per person

  • Your score is the number of entries

against which you win more than 50.00001% of the time

  • Strategies are time-limited
  • All strategies must be deterministic,

pure functions of the players' scores

  • Winning entries will receive a paltry

amount of extra credit

  • The real prize: honor and glory
  • See website for detailed rules

3

cs61a.org/proj/hog_contest Kaylee Mann Yan Duan & Ziming Li Brian Prike & Zhenghao Qian Parker Schuh & Robert Chatham Fall 2011 Winners Chenyang Yuan Joseph Hui Fall 2012 Winners

slide-13
SLIDE 13

Hog Contest Rules

  • Up to two people submit one entry;

Max of one entry per person

  • Your score is the number of entries

against which you win more than 50.00001% of the time

  • Strategies are time-limited
  • All strategies must be deterministic,

pure functions of the players' scores

  • Winning entries will receive a paltry

amount of extra credit

  • The real prize: honor and glory
  • See website for detailed rules

3

cs61a.org/proj/hog_contest Kaylee Mann Yan Duan & Ziming Li Brian Prike & Zhenghao Qian Parker Schuh & Robert Chatham Fall 2011 Winners Chenyang Yuan Joseph Hui Fall 2012 Winners Paul Bramsen Sam Kumar & Kangsik Lee Kevin Chen Fall 2013 Winners

slide-14
SLIDE 14

Hog Contest Rules

  • Up to two people submit one entry;

Max of one entry per person

  • Your score is the number of entries

against which you win more than 50.00001% of the time

  • Strategies are time-limited
  • All strategies must be deterministic,

pure functions of the players' scores

  • Winning entries will receive a paltry

amount of extra credit

  • The real prize: honor and glory
  • See website for detailed rules

3

cs61a.org/proj/hog_contest Kaylee Mann Yan Duan & Ziming Li Brian Prike & Zhenghao Qian Parker Schuh & Robert Chatham Fall 2011 Winners Chenyang Yuan Joseph Hui Fall 2012 Winners Paul Bramsen Sam Kumar & Kangsik Lee Kevin Chen Fall 2013 Winners Alan Tong & Elaine Zhao Zhenyang Zhang Adam Robert Villaflor & Joany Gao Zhen Qin & Dian Chen Zizheng Tai & Yihe Li Fall 2014 Winners

slide-15
SLIDE 15

Hog Contest Winners

4

Sinho Chewi & Alexander Nguyen Tran Zhaoxi Li Stella Tao and Yao Ge Spring 2015 Winners

slide-16
SLIDE 16

Hog Contest Winners

4

Sinho Chewi & Alexander Nguyen Tran Zhaoxi Li Stella Tao and Yao Ge Spring 2015 Winners Micah Carroll & Vasilis Oikonomou Matthew Wu Anthony Yeung and Alexander Dai Fall 2015 Winners

slide-17
SLIDE 17

Hog Contest Winners

4

Sinho Chewi & Alexander Nguyen Tran Zhaoxi Li Stella Tao and Yao Ge Spring 2015 Winners Micah Carroll & Vasilis Oikonomou Matthew Wu Anthony Yeung and Alexander Dai Fall 2015 Winners Spring 2016 Winners Michael McDonald and Tianrui Chen Andrei Kassiantchouk Benjamin Krieges

slide-18
SLIDE 18

Hog Contest Winners

4

Sinho Chewi & Alexander Nguyen Tran Zhaoxi Li Stella Tao and Yao Ge Spring 2015 Winners Micah Carroll & Vasilis Oikonomou Matthew Wu Anthony Yeung and Alexander Dai Fall 2015 Winners Spring 2016 Winners Michael McDonald and Tianrui Chen Andrei Kassiantchouk Benjamin Krieges Fall 2016 Winners Cindy Jin and Sunjoon Lee Anny Patino and Christian Vasquez Asana Choudhury and Jenna Wen Michelle Lee and Nicholas Chew

slide-19
SLIDE 19

Hog Contest Winners

4

Sinho Chewi & Alexander Nguyen Tran Zhaoxi Li Stella Tao and Yao Ge Spring 2015 Winners Micah Carroll & Vasilis Oikonomou Matthew Wu Anthony Yeung and Alexander Dai Fall 2015 Winners Spring 2016 Winners Michael McDonald and Tianrui Chen Andrei Kassiantchouk Benjamin Krieges Fall 2016 Winners Cindy Jin and Sunjoon Lee Anny Patino and Christian Vasquez Asana Choudhury and Jenna Wen Michelle Lee and Nicholas Chew Fall 2017 Winners Alex Yu and Tanmay Khattar James Li Justin Yokota

slide-20
SLIDE 20

Hog Contest Winners

4

Sinho Chewi & Alexander Nguyen Tran Zhaoxi Li Stella Tao and Yao Ge Spring 2015 Winners Micah Carroll & Vasilis Oikonomou Matthew Wu Anthony Yeung and Alexander Dai Fall 2015 Winners Spring 2016 Winners Michael McDonald and Tianrui Chen Andrei Kassiantchouk Benjamin Krieges Fall 2016 Winners Cindy Jin and Sunjoon Lee Anny Patino and Christian Vasquez Asana Choudhury and Jenna Wen Michelle Lee and Nicholas Chew Fall 2017 Winners Alex Yu and Tanmay Khattar James Li Justin Yokota Spring 2018 Winners Eric James Michaud Ziyu Dong Xuhui Zhou

slide-21
SLIDE 21

Hog Contest Winners

4

Sinho Chewi & Alexander Nguyen Tran Zhaoxi Li Stella Tao and Yao Ge Spring 2015 Winners Micah Carroll & Vasilis Oikonomou Matthew Wu Anthony Yeung and Alexander Dai Fall 2015 Winners Spring 2016 Winners Michael McDonald and Tianrui Chen Andrei Kassiantchouk Benjamin Krieges Fall 2016 Winners Cindy Jin and Sunjoon Lee Anny Patino and Christian Vasquez Asana Choudhury and Jenna Wen Michelle Lee and Nicholas Chew Fall 2017 Winners Alex Yu and Tanmay Khattar James Li Justin Yokota Spring 2018 Winners Eric James Michaud Ziyu Dong Xuhui Zhou Fall 2018 Winners Rahul Arya Jonathan Bodine Sumer Kohli and Neelesh Ramachandran

slide-22
SLIDE 22

Hog Contest Winners

4

Sinho Chewi & Alexander Nguyen Tran Zhaoxi Li Stella Tao and Yao Ge Spring 2015 Winners Micah Carroll & Vasilis Oikonomou Matthew Wu Anthony Yeung and Alexander Dai Fall 2015 Winners Spring 2016 Winners Michael McDonald and Tianrui Chen Andrei Kassiantchouk Benjamin Krieges Fall 2016 Winners Cindy Jin and Sunjoon Lee Anny Patino and Christian Vasquez Asana Choudhury and Jenna Wen Michelle Lee and Nicholas Chew Fall 2017 Winners Alex Yu and Tanmay Khattar James Li Justin Yokota Spring 2018 Winners Eric James Michaud Ziyu Dong Xuhui Zhou Fall 2019 Winners Fall 2018 Winners Rahul Arya Jonathan Bodine Sumer Kohli and Neelesh Ramachandran

slide-23
SLIDE 23

Hog Contest Winners

4

Sinho Chewi & Alexander Nguyen Tran Zhaoxi Li Stella Tao and Yao Ge Spring 2015 Winners Micah Carroll & Vasilis Oikonomou Matthew Wu Anthony Yeung and Alexander Dai Fall 2015 Winners Spring 2016 Winners Michael McDonald and Tianrui Chen Andrei Kassiantchouk Benjamin Krieges Fall 2016 Winners Cindy Jin and Sunjoon Lee Anny Patino and Christian Vasquez Asana Choudhury and Jenna Wen Michelle Lee and Nicholas Chew Fall 2017 Winners Alex Yu and Tanmay Khattar James Li Justin Yokota Spring 2018 Winners Eric James Michaud Ziyu Dong Xuhui Zhou Fall 2019 Winners Fall 2018 Winners Rahul Arya Jonathan Bodine Sumer Kohli and Neelesh Ramachandran Jet Situ and Lucas Schaberg Anthony Han and Hongyi Huang Arthur Pan and Qingyuan Liu

slide-24
SLIDE 24

Hog Contest Winners

4

Sinho Chewi & Alexander Nguyen Tran Zhaoxi Li Stella Tao and Yao Ge Spring 2015 Winners Micah Carroll & Vasilis Oikonomou Matthew Wu Anthony Yeung and Alexander Dai Fall 2015 Winners Spring 2016 Winners Michael McDonald and Tianrui Chen Andrei Kassiantchouk Benjamin Krieges Fall 2016 Winners Cindy Jin and Sunjoon Lee Anny Patino and Christian Vasquez Asana Choudhury and Jenna Wen Michelle Lee and Nicholas Chew Fall 2017 Winners Alex Yu and Tanmay Khattar James Li Justin Yokota Spring 2018 Winners Eric James Michaud Ziyu Dong Xuhui Zhou Fall 2019 Winners Fall 2018 Winners Rahul Arya Jonathan Bodine Sumer Kohli and Neelesh Ramachandran Spring 2020 Winners Jet Situ and Lucas Schaberg Anthony Han and Hongyi Huang Arthur Pan and Qingyuan Liu

slide-25
SLIDE 25

Hog Contest Winners

4

Sinho Chewi & Alexander Nguyen Tran Zhaoxi Li Stella Tao and Yao Ge Spring 2015 Winners Micah Carroll & Vasilis Oikonomou Matthew Wu Anthony Yeung and Alexander Dai Fall 2015 Winners Spring 2016 Winners Michael McDonald and Tianrui Chen Andrei Kassiantchouk Benjamin Krieges Fall 2016 Winners Cindy Jin and Sunjoon Lee Anny Patino and Christian Vasquez Asana Choudhury and Jenna Wen Michelle Lee and Nicholas Chew Fall 2017 Winners Alex Yu and Tanmay Khattar James Li Justin Yokota Spring 2018 Winners Eric James Michaud Ziyu Dong Xuhui Zhou Fall 2019 Winners Fall 2018 Winners Rahul Arya Jonathan Bodine Sumer Kohli and Neelesh Ramachandran Spring 2020 Winners Andy Dong Theodor Sion and Anish Kar Shaun Diem-Lane Jet Situ and Lucas Schaberg Anthony Han and Hongyi Huang Arthur Pan and Qingyuan Liu

slide-26
SLIDE 26

Hog Contest Winners

4

Sinho Chewi & Alexander Nguyen Tran Zhaoxi Li Stella Tao and Yao Ge Spring 2015 Winners Micah Carroll & Vasilis Oikonomou Matthew Wu Anthony Yeung and Alexander Dai Fall 2015 Winners Spring 2016 Winners Michael McDonald and Tianrui Chen Andrei Kassiantchouk Benjamin Krieges Fall 2016 Winners Cindy Jin and Sunjoon Lee Anny Patino and Christian Vasquez Asana Choudhury and Jenna Wen Michelle Lee and Nicholas Chew Fall 2017 Winners Alex Yu and Tanmay Khattar James Li Justin Yokota Spring 2018 Winners Eric James Michaud Ziyu Dong Xuhui Zhou Fall 2019 Winners Fall 2018 Winners Rahul Arya Jonathan Bodine Sumer Kohli and Neelesh Ramachandran Spring 2020 Winners Fall 2020 Winners Andy Dong Theodor Sion and Anish Kar Shaun Diem-Lane Jet Situ and Lucas Schaberg Anthony Han and Hongyi Huang Arthur Pan and Qingyuan Liu

slide-27
SLIDE 27

Hog Contest Winners

4

Sinho Chewi & Alexander Nguyen Tran Zhaoxi Li Stella Tao and Yao Ge Spring 2015 Winners Micah Carroll & Vasilis Oikonomou Matthew Wu Anthony Yeung and Alexander Dai Fall 2015 Winners Spring 2016 Winners Michael McDonald and Tianrui Chen Andrei Kassiantchouk Benjamin Krieges Fall 2016 Winners Cindy Jin and Sunjoon Lee Anny Patino and Christian Vasquez Asana Choudhury and Jenna Wen Michelle Lee and Nicholas Chew Fall 2017 Winners Alex Yu and Tanmay Khattar James Li Justin Yokota

Your name could be here FOREVER!

Spring 2018 Winners Eric James Michaud Ziyu Dong Xuhui Zhou Fall 2019 Winners Fall 2018 Winners Rahul Arya Jonathan Bodine Sumer Kohli and Neelesh Ramachandran Spring 2020 Winners Fall 2020 Winners Andy Dong Theodor Sion and Anish Kar Shaun Diem-Lane Jet Situ and Lucas Schaberg Anthony Han and Hongyi Huang Arthur Pan and Qingyuan Liu

slide-28
SLIDE 28

Describing Functions

slide-29
SLIDE 29

Boolean Favorites

6

def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): k = 1 while k < n: if likes(n): print(k) k = k + 2

mystery1 prints ______ less than n ______ .

slide-30
SLIDE 30

Boolean Favorites

6

def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): k = 1 while k < n: if likes(n): print(k) k = k + 2

mystery1 prints ______ less than n ______ . One approach:

slide-31
SLIDE 31

Boolean Favorites

6

def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): k = 1 while k < n: if likes(n): print(k) k = k + 2

mystery1 prints ______ less than n ______ . One approach:

  • 1. Read the code
slide-32
SLIDE 32

Boolean Favorites

6

def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): k = 1 while k < n: if likes(n): print(k) k = k + 2

mystery1 prints ______ less than n ______ . One approach:

  • 1. Read the code
  • 2. Read the description options
slide-33
SLIDE 33

Boolean Favorites

6

def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): k = 1 while k < n: if likes(n): print(k) k = k + 2

mystery1 prints ______ less than n ______ . One approach:

  • 1. Read the code
  • 2. Read the description options
  • 3. Consider an example
slide-34
SLIDE 34

Boolean Favorites

6

def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): k = 1 while k < n: if likes(n): print(k) k = k + 2

mystery1 prints ______ less than n ______ . One approach:

  • 1. Read the code
  • 2. Read the description options
  • 3. Consider an example

mystery1 prints all odd numbers less than n that George likes.

slide-35
SLIDE 35

Boolean Favorites

6

def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): k = 1 while k < n: if likes(n): print(k) k = k + 2

mystery1 prints ______ less than n ______ . One approach:

  • 1. Read the code
  • 2. Read the description options
  • 3. Consider an example

mystery1 prints all odd numbers less than n that George likes. likes = is_prime n = 8

slide-36
SLIDE 36

Boolean Favorites

6

def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): k = 1 while k < n: if likes(n): print(k) k = k + 2

mystery1 prints ______ less than n ______ . One approach:

  • 1. Read the code
  • 2. Read the description options
  • 3. Consider an example

mystery1 prints all odd numbers less than n that George likes. likes = is_prime n = 8

slide-37
SLIDE 37

Boolean Favorites

6

def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): k = 1 while k < n: if likes(n): print(k) k = k + 2

mystery1 prints ______ less than n ______ . One approach:

  • 1. Read the code
  • 2. Read the description options
  • 3. Consider an example

all odd numbers mystery1 prints all odd numbers less than n that George likes. likes = is_prime n = 8

slide-38
SLIDE 38

Boolean Favorites

6

def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): k = 1 while k < n: if likes(n): print(k) k = k + 2

mystery1 prints ______ less than n ______ . One approach:

  • 1. Read the code
  • 2. Read the description options
  • 3. Consider an example

all odd numbers but only if George likes n mystery1 prints all odd numbers less than n that George likes. likes = is_prime n = 8

slide-39
SLIDE 39

Boolean Favorites

7

def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery2(n): i, j, k = 0, None, None while i < n: if likes(i): if j != None and (k == None or i - j < k): k = i - j j = i i = i + 1 return k

One approach:

  • 1. Read the code
  • 2. Read the description options
  • 3. Consider an example

mystery 2 returns ______ or returns None if ______ .

slide-40
SLIDE 40

Boolean Favorites

7

def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery2(n): i, j, k = 0, None, None while i < n: if likes(i): if j != None and (k == None or i - j < k): k = i - j j = i i = i + 1 return k

One approach:

  • 1. Read the code
  • 2. Read the description options
  • 3. Consider an example

mystery 2 returns ______ or returns None if ______ . the smallest difference between two positive integers below n that George likes

slide-41
SLIDE 41

Boolean Favorites

7

def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery2(n): i, j, k = 0, None, None while i < n: if likes(i): if j != None and (k == None or i - j < k): k = i - j j = i i = i + 1 return k

One approach:

  • 1. Read the code
  • 2. Read the description options
  • 3. Consider an example

mystery 2 returns ______ or returns None if ______ . the smallest difference between two positive integers below n that George likes There are no two such integers

slide-42
SLIDE 42

Generating Environment Diagram

slide-43
SLIDE 43

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)

slide-44
SLIDE 44

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)

slide-45
SLIDE 45

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)

slide-46
SLIDE 46

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)

slide-47
SLIDE 47

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)

slide-48
SLIDE 48

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)

slide-49
SLIDE 49

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)

slide-50
SLIDE 50

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)

slide-51
SLIDE 51

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)

slide-52
SLIDE 52

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)

slide-53
SLIDE 53

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip

slide-54
SLIDE 54

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip

slide-55
SLIDE 55

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip flop(1)

slide-56
SLIDE 56

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip flop(1)

slide-57
SLIDE 57

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip flop(1) not true for flop == 1

slide-58
SLIDE 58

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip flop(1) not true for flop == 1 lambda flip: 3

slide-59
SLIDE 59

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip flop(1) not true for flop == 1 lambda flip: 3

slide-60
SLIDE 60

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip flop(1) not true for flop == 1 lambda flip: 3

slide-61
SLIDE 61

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip flop(1) not true for flop == 1 lambda flip: 3

slide-62
SLIDE 62

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip flop(1)(2) not true for flop == 1 lambda flip: 3

slide-63
SLIDE 63

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip flop(1)(2) not true for flop == 1 lambda flip: 3

slide-64
SLIDE 64

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip flop(1)(2) not true for flop == 1 lambda flip: 3

slide-65
SLIDE 65

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip flop(1)(2) not true for flop == 1 lambda flip: 3

slide-66
SLIDE 66

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip flop(1)(2) not true for flop == 1 lambda flip: 3

slide-67
SLIDE 67

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip flop(1)(2) not true for flop == 1 lambda flip: 3 true for flop == 3

slide-68
SLIDE 68

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip flop(1)(2) not true for flop == 1 lambda flip: 3 true for flop == 3 flop>2

slide-69
SLIDE 69

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip flop(1)(2) not true for flop == 1 lambda flip: 3 true for flop == 3 flop>2 return None

slide-70
SLIDE 70

A Day at the Beach

9

def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) flip, flop = flop, flip flop(1)(2) not true for flop == 1 lambda flip: 3 true for flop == 3 flop>2 return None

slide-71
SLIDE 71

Implementing Functions

slide-72
SLIDE 72

Implementing a Function

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________

slide-73
SLIDE 73

Implementing a Function

Read the description

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________

slide-74
SLIDE 74

Implementing a Function

Read the description Verify the examples & pick a simple one

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________

slide-75
SLIDE 75

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________

slide-76
SLIDE 76

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it.

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________

slide-77
SLIDE 77

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________

slide-78
SLIDE 78

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________

slide-79
SLIDE 79

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing?

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________

slide-80
SLIDE 80

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________

slide-81
SLIDE 81

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3

slide-82
SLIDE 82

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21

slide-83
SLIDE 83

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0

slide-84
SLIDE 84

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit

slide-85
SLIDE 85

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit kept

slide-86
SLIDE 86

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit kept + last kept

slide-87
SLIDE 87

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit kept + last kept 10*

slide-88
SLIDE 88

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit kept + last kept 10*

slide-89
SLIDE 89

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit kept + last kept *10 10*

slide-90
SLIDE 90

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit kept + last kept *10 10* 1 + 20 21

slide-91
SLIDE 91

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit kept + last kept digits + 1 *10 10* 1 + 20 21

slide-92
SLIDE 92

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit kept + last kept digits + 1 *10 10* **digits 1 + 20 21

slide-93
SLIDE 93

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit kept + last kept digits + 1 *10 10* 4 **digits 1 + 20 21

slide-94
SLIDE 94

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit kept + last kept digits + 1 *10 10* 4 **digits 231 1 + 20 21

slide-95
SLIDE 95

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

11

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit kept + last kept digits + 1 *10 10* 4 **digits 231 1 + 30 + 200 231 1 + 20 21

slide-96
SLIDE 96

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

12

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit kept + last kept

slide-97
SLIDE 97

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

12

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit kept + last kept /10

slide-98
SLIDE 98

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

12

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit kept + last kept /10 * 10

slide-99
SLIDE 99

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

12

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit kept + last kept /10 * 10 digits + 1

slide-100
SLIDE 100

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

12

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit kept + last kept /10 * 10 ** (digits-1) digits + 1

slide-101
SLIDE 101

Implementing a Function

Read the description Verify the examples & pick a simple one Read the template Implement without the template, then change your implementation to match the template. OR If the template is helpful, use it. Annotate names with values from your chosen example Write code to compute the result Did you really return the right thing? Check your solution with the other examples

12

def remove(n, digit): """Return all digits of non-negative N that are not DIGIT, for some non-negative DIGIT less than 10. >>> remove(231, 3) 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 231 3 21 n > 0 last != digit kept + last kept /10 * 10 ** (digits-1) digits + 1 round( )

slide-102
SLIDE 102

Decorators

slide-103
SLIDE 103

Function Decorators

(Demo)

14

slide-104
SLIDE 104

Function Decorators

(Demo) @trace1 def triple(x): return 3 * x

14

slide-105
SLIDE 105

Function Decorators

(Demo) @trace1 def triple(x): return 3 * x Function decorator

14

slide-106
SLIDE 106

Function Decorators

(Demo) @trace1 def triple(x): return 3 * x Decorated function Function decorator

14

slide-107
SLIDE 107

Function Decorators

(Demo) @trace1 def triple(x): return 3 * x is identical to Decorated function Function decorator

14

slide-108
SLIDE 108

Function Decorators

(Demo) @trace1 def triple(x): return 3 * x is identical to def triple(x): return 3 * x triple = trace1(triple) Decorated function Function decorator

14

slide-109
SLIDE 109

Function Decorators

(Demo) @trace1 def triple(x): return 3 * x is identical to def triple(x): return 3 * x triple = trace1(triple) Decorated function Why not just use this? Function decorator

14