Hog Contest Winners Fall 2017 Winners Alex Yu and Tanmay Khattar Spring 2015 Winners James Li Sinho Chewi & Alexander Nguyen Tran Justin Yokota Zhaoxi Li Spring 2018 Winners Stella Tao and Yao Ge Eric James Michaud Ziyu Dong Fall 2015 Winners Xuhui Zhou Micah Carroll & Vasilis Oikonomou Fall 2018 Winners Matthew Wu Rahul Arya Anthony Yeung and Alexander Dai Jonathan Bodine Sumer Kohli and Neelesh Ramachandran Spring 2016 Winners Fall 2019 Winners Michael McDonald and Tianrui Chen Jet Situ and Lucas Schaberg Andrei Kassiantchouk Anthony Han and Hongyi Huang Benjamin Krieges Arthur Pan and Qingyuan Liu Spring 2020 Winners Fall 2016 Winners Cindy Jin and Sunjoon Lee Anny Patino and Christian Vasquez Asana Choudhury and Jenna Wen Michelle Lee and Nicholas Chew 4
Hog Contest Winners Fall 2017 Winners Alex Yu and Tanmay Khattar Spring 2015 Winners James Li Sinho Chewi & Alexander Nguyen Tran Justin Yokota Zhaoxi Li Spring 2018 Winners Stella Tao and Yao Ge Eric James Michaud Ziyu Dong Fall 2015 Winners Xuhui Zhou Micah Carroll & Vasilis Oikonomou Fall 2018 Winners Matthew Wu Rahul Arya Anthony Yeung and Alexander Dai Jonathan Bodine Sumer Kohli and Neelesh Ramachandran Spring 2016 Winners Fall 2019 Winners Michael McDonald and Tianrui Chen Jet Situ and Lucas Schaberg Andrei Kassiantchouk Anthony Han and Hongyi Huang Benjamin Krieges Arthur Pan and Qingyuan Liu Spring 2020 Winners Fall 2016 Winners Andy Dong Cindy Jin and Sunjoon Lee Theodor Sion and Anish Kar Anny Patino and Christian Vasquez Shaun Diem-Lane Asana Choudhury and Jenna Wen Michelle Lee and Nicholas Chew 4
Hog Contest Winners Fall 2017 Winners Alex Yu and Tanmay Khattar Spring 2015 Winners James Li Sinho Chewi & Alexander Nguyen Tran Justin Yokota Zhaoxi Li Spring 2018 Winners Stella Tao and Yao Ge Eric James Michaud Ziyu Dong Fall 2015 Winners Xuhui Zhou Micah Carroll & Vasilis Oikonomou Fall 2018 Winners Matthew Wu Rahul Arya Anthony Yeung and Alexander Dai Jonathan Bodine Sumer Kohli and Neelesh Ramachandran Spring 2016 Winners Fall 2019 Winners Michael McDonald and Tianrui Chen Jet Situ and Lucas Schaberg Andrei Kassiantchouk Anthony Han and Hongyi Huang Benjamin Krieges Arthur Pan and Qingyuan Liu Spring 2020 Winners Fall 2016 Winners Andy Dong Cindy Jin and Sunjoon Lee Theodor Sion and Anish Kar Anny Patino and Christian Vasquez Shaun Diem-Lane Asana Choudhury and Jenna Wen Fall 2020 Winners Michelle Lee and Nicholas Chew 4
Hog Contest Winners Fall 2017 Winners Alex Yu and Tanmay Khattar Spring 2015 Winners Your name could be here FOREVER! James Li Sinho Chewi & Alexander Nguyen Tran Justin Yokota Zhaoxi Li Spring 2018 Winners Stella Tao and Yao Ge Eric James Michaud Ziyu Dong Fall 2015 Winners Xuhui Zhou Micah Carroll & Vasilis Oikonomou Fall 2018 Winners Matthew Wu Rahul Arya Anthony Yeung and Alexander Dai Jonathan Bodine Sumer Kohli and Neelesh Ramachandran Spring 2016 Winners Fall 2019 Winners Michael McDonald and Tianrui Chen Jet Situ and Lucas Schaberg Andrei Kassiantchouk Anthony Han and Hongyi Huang Benjamin Krieges Arthur Pan and Qingyuan Liu Spring 2020 Winners Fall 2016 Winners Andy Dong Cindy Jin and Sunjoon Lee Theodor Sion and Anish Kar Anny Patino and Christian Vasquez Shaun Diem-Lane Asana Choudhury and Jenna Wen Fall 2020 Winners Michelle Lee and Nicholas Chew 4
Describing Functions
Boolean Favorites 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 ______ . 6
Boolean Favorites def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): One approach: k = 1 while k < n: if likes(n): print(k) k = k + 2 mystery1 prints ______ less than n ______ . 6
Boolean Favorites def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): One approach: k = 1 1. Read the code while k < n: if likes(n): print(k) k = k + 2 mystery1 prints ______ less than n ______ . 6
Boolean Favorites def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): One approach: k = 1 1. Read the code while k < n: 2. Read the description options if likes(n): print(k) k = k + 2 mystery1 prints ______ less than n ______ . 6
Boolean Favorites def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): One approach: k = 1 1. Read the code while k < n: 2. Read the description options if likes(n): 3. Consider an example print(k) k = k + 2 mystery1 prints ______ less than n ______ . 6
Boolean Favorites def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): One approach: k = 1 1. Read the code while k < n: 2. Read the description options if likes(n): 3. Consider an example print(k) k = k + 2 mystery1 prints ______ less than n ______ . mystery1 prints all odd numbers less than n that George likes. 6
Boolean Favorites def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): likes = is_prime One approach: n = 8 k = 1 1. Read the code while k < n: 2. Read the description options if likes(n): 3. Consider an example print(k) k = k + 2 mystery1 prints ______ less than n ______ . mystery1 prints all odd numbers less than n that George likes. 6
Boolean Favorites def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): likes = is_prime One approach: n = 8 k = 1 1. Read the code while k < n: 2. Read the description options if likes(n): 3. Consider an example print(k) k = k + 2 mystery1 prints ______ less than n ______ . mystery1 prints all odd numbers less than n that George likes. 6
Boolean Favorites def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): likes = is_prime One approach: n = 8 k = 1 1. Read the code while k < n: 2. Read the description options if likes(n): 3. Consider an example print(k) k = k + 2 all odd numbers mystery1 prints ______ less than n ______ . mystery1 prints all odd numbers less than n that George likes. 6
Boolean Favorites def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): likes = is_prime One approach: n = 8 k = 1 1. Read the code while k < n: 2. Read the description options if likes(n): 3. Consider an example print(k) k = k + 2 all odd numbers but only if George likes n mystery1 prints ______ less than n ______ . mystery1 prints all odd numbers less than n that George likes. 6
Boolean Favorites def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery2(n): One approach: i, j, k = 0, None, None 1. Read the code while i < n: 2. Read the description options if likes(i): 3. Consider an example if j != None and (k == None or i - j < k): k = i - j j = i i = i + 1 return k mystery 2 returns ______ or returns None if ______ . 7
Boolean Favorites def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery2(n): One approach: i, j, k = 0, None, None 1. Read the code while i < n: 2. Read the description options if likes(i): 3. Consider an example if j != None and (k == None or i - j < k): k = i - j j = i i = i + 1 return k the smallest difference between two positive integers below n that George likes mystery 2 returns ______ or returns None if ______ . 7
Boolean Favorites def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery2(n): One approach: i, j, k = 0, None, None 1. Read the code while i < n: 2. Read the description options if likes(i): 3. Consider an example if j != None and (k == None or i - j < k): k = i - j j = i i = i + 1 return k the smallest difference between There are no two two positive integers below n such integers that George likes mystery 2 returns ______ or returns None if ______ . 7
Generating Environment Diagram
A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9
A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9
A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9
A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9
A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9
A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9
A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9
A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9
A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9
A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9
A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) 9
A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) 9
A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) flop(1) 9
A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) flop(1) 9
A Day at the Beach def flip(flop): not true for flop == 1 if ______: ______ flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) flop(1) 9
A Day at the Beach def flip(flop): not true for flop == 1 if ______: ______ lambda flip: 3 flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) flop(1) 9
A Day at the Beach def flip(flop): not true for flop == 1 if ______: ______ lambda flip: 3 flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) flop(1) 9
A Day at the Beach def flip(flop): not true for flop == 1 if ______: ______ lambda flip: 3 flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) flop(1) 9
A Day at the Beach def flip(flop): not true for flop == 1 if ______: ______ lambda flip: 3 flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) flop(1) 9
A Day at the Beach def flip(flop): not true for flop == 1 if ______: ______ lambda flip: 3 flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) flop(1)(2) 9
A Day at the Beach def flip(flop): not true for flop == 1 if ______: ______ lambda flip: 3 flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) flop(1)(2) 9
A Day at the Beach def flip(flop): not true for flop == 1 if ______: ______ lambda flip: 3 flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) flop(1)(2) 9
A Day at the Beach def flip(flop): not true for flop == 1 if ______: ______ lambda flip: 3 flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) flop(1)(2) 9
A Day at the Beach def flip(flop): not true for flop == 1 if ______: ______ lambda flip: 3 flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) flop(1)(2) 9
A Day at the Beach def flip(flop): not true for flop == 1 if ______: true for flop == 3 ______ lambda flip: 3 flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) flop(1)(2) 9
A Day at the Beach def flip(flop): not true for flop == 1 flop>2 if ______: true for flop == 3 ______ lambda flip: 3 flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) flop(1)(2) 9
A Day at the Beach def flip(flop): not true for flop == 1 flop>2 if ______: true for flop == 3 return None ______ lambda flip: 3 flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) flop(1)(2) 9
A Day at the Beach def flip(flop): not true for flop == 1 flop>2 if ______: true for flop == 3 return None ______ lambda flip: 3 flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) flop(1)(2) 9
Implementing Functions
Implementing a Function 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 _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """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 _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some Verify the examples & pick a simple one 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 _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) 4313 """ kept, digits = 0, 0 while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. while ________________________________: n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 Write code to compute the result if _______________________________: kept = _______________________ digits = _____________________ return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 Write code to compute the result if _______________________________: Did you really return the right thing? kept = _______________________ digits = _____________________ return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 Write code to compute the result if _______________________________: Did you really return the right thing? kept = _______________________ digits = _____________________ Check your solution with the other examples return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 Write code to compute the result if _______________________________: Did you really return the right thing? kept = _______________________ digits = _____________________ Check your solution with the other examples return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 Write code to compute the result if _______________________________: Did you really return the right thing? kept = _______________________ 21 digits = _____________________ Check your solution with the other examples return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 Write code to compute the result if _______________________________: Did you really return the right thing? kept = _______________________ 21 digits = _____________________ Check your solution with the other examples return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: Did you really return the right thing? kept = _______________________ 21 digits = _____________________ Check your solution with the other examples return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: Did you really return the right thing? kept = _______________________ 21 digits = _____________________ Check your solution with the other examples kept return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: kept + last Did you really return the right thing? kept = _______________________ 21 digits = _____________________ Check your solution with the other examples kept return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: 10* kept + last Did you really return the right thing? kept = _______________________ 21 digits = _____________________ Check your solution with the other examples kept return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: 10* kept + last Did you really return the right thing? kept = _______________________ 21 digits = _____________________ Check your solution with the other examples kept return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: 10* kept + last *10 Did you really return the right thing? kept = _______________________ 21 digits = _____________________ Check your solution with the other examples kept return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. 1 >>> remove(231, 3) Read the template 21 + 20 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR 21 kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: 10* kept + last *10 Did you really return the right thing? kept = _______________________ 21 digits = _____________________ Check your solution with the other examples kept return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. 1 >>> remove(231, 3) Read the template 21 + 20 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR 21 kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: 10* kept + last *10 Did you really return the right thing? kept = _______________________ digits + 1 21 digits = _____________________ Check your solution with the other examples kept return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. 1 >>> remove(231, 3) Read the template 21 + 20 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR 21 kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: **digits 10* kept + last *10 Did you really return the right thing? kept = _______________________ digits + 1 21 digits = _____________________ Check your solution with the other examples kept return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 4 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. 1 >>> remove(231, 3) Read the template 21 + 20 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR 21 kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: **digits 10* kept + last *10 Did you really return the right thing? kept = _______________________ digits + 1 21 digits = _____________________ Check your solution with the other examples kept return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 4 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. 1 >>> remove(231, 3) Read the template 21 + 20 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR 21 kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: **digits 10* kept + last *10 Did you really return the right thing? kept = _______________________ digits + 1 231 21 digits = _____________________ Check your solution with the other examples kept return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 4 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. 1 1 >>> remove(231, 3) Read the template 21 + 20 + 30 >>> remove(243132, 2) Implement without the template, then change 4313 + 200 your implementation to match the template. """ OR 21 231 kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: **digits 10* kept + last *10 Did you really return the right thing? kept = _______________________ digits + 1 231 21 digits = _____________________ Check your solution with the other examples kept return _______________________________ 11
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: kept + last Did you really return the right thing? kept = _______________________ 21 digits = _____________________ Check your solution with the other examples kept return _______________________________ 12
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: kept + last /10 Did you really return the right thing? kept = _______________________ 21 digits = _____________________ Check your solution with the other examples kept return _______________________________ 12
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: kept + last /10 Did you really return the right thing? kept = _______________________ 21 digits = _____________________ Check your solution with the other examples kept * 10 return _______________________________ 12
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: kept + last /10 Did you really return the right thing? kept = _______________________ digits + 1 21 digits = _____________________ Check your solution with the other examples kept * 10 return _______________________________ 12
Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: kept + last /10 Did you really return the right thing? kept = _______________________ digits + 1 21 digits = _____________________ Check your solution with the other examples kept * 10 ** (digits-1) return _______________________________ 12
Recommend
More recommend