SLIDE 1
Function Examples Announcements Hog Contest Rules 3 - - PowerPoint PPT Presentation
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 2
SLIDE 3
Hog Contest Rules
3
cs61a.org/proj/hog_contest
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
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
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
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
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
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
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
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
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
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
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
Hog Contest Winners
4
Sinho Chewi & Alexander Nguyen Tran Zhaoxi Li Stella Tao and Yao Ge Spring 2015 Winners
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
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
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
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
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
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
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
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
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
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
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
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
Describing Functions
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
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
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
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
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
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
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
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
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
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
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
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
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
Generating Environment Diagram
SLIDE 43
A Day at the Beach
9
def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)
SLIDE 44
A Day at the Beach
9
def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)
SLIDE 45
A Day at the Beach
9
def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)
SLIDE 46
A Day at the Beach
9
def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)
SLIDE 47
A Day at the Beach
9
def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)
SLIDE 48
A Day at the Beach
9
def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)
SLIDE 49
A Day at the Beach
9
def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)
SLIDE 50
A Day at the Beach
9
def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)
SLIDE 51
A Day at the Beach
9
def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)
SLIDE 52
A Day at the Beach
9
def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3)
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Implementing Functions
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Decorators
SLIDE 103
Function Decorators
(Demo)
14
SLIDE 104
Function Decorators
(Demo) @trace1 def triple(x): return 3 * x
14
SLIDE 105
Function Decorators
(Demo) @trace1 def triple(x): return 3 * x Function decorator
14
SLIDE 106
Function Decorators
(Demo) @trace1 def triple(x): return 3 * x Decorated function Function decorator
14
SLIDE 107
Function Decorators
(Demo) @trace1 def triple(x): return 3 * x is identical to Decorated function Function decorator
14
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
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