function examples announcements hog contest rules
play

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


  1. 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

  2. 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

  3. 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

  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

  5. Describing Functions

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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

  11. 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

  12. 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

  13. 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

  14. 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

  15. 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

  16. 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

  17. 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

  18. 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

  19. Generating Environment Diagram

  20. A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9

  21. A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9

  22. A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9

  23. A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9

  24. A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9

  25. A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9

  26. A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9

  27. A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9

  28. A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9

  29. A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop ______ flip(____)(3) 9

  30. A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) 9

  31. A Day at the Beach def flip(flop): if ______: ______ flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) 9

  32. 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

  33. 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

  34. 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

  35. 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

  36. 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

  37. 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

  38. 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

  39. 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

  40. 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

  41. 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

  42. 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

  43. 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

  44. 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

  45. 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

  46. 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

  47. 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

  48. Implementing Functions

  49. 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

  50. 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

  51. 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

  52. 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

  53. 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

  54. 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

  55. 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

  56. 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

  57. 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

  58. 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

  59. 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

  60. 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

  61. 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

  62. 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

  63. 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

  64. 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

  65. 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

  66. 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

  67. 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

  68. 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

  69. 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

  70. 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

  71. 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

  72. 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

  73. 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

  74. 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

  75. 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

  76. 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

  77. 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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend