diff --git a/disc/disc03/index.html b/disc/disc03/index.html index dbf89b7437..f02e5e6f72 100644 --- a/disc/disc03/index.html +++ b/disc/disc03/index.html @@ -2,9 +2,9 @@
- + - + @@ -12,8 +12,8 @@ - - + + - + - - - + + + @@ -37,7 +37,7 @@Pick someone in your group to join Discord. -It's fine if multiple people join, but one is enough.
+If there are fewer than 3 people in your group, feel free to merge your group with another group in the room.
Now switch to Pensieve:
Once you're on Pensieve, you don't need to return to this page; Pensieve has all the same content (but more features). If for some reason Penseive doesn't work, return to this page and continue with the discussion.
-Post in the #help
channel on Discord if you have trouble.
Say your name and share a food that you really liked as a child. (It's ok if you still like that food now.)
-Suggestion: After Midterm 1, some students are looking for more effective -ways to study. One great option is to meet up with your discussion group outside -of class to review practice problems together. Now is a great time to schedule a -time and place for some extra group practice of old Midterm 1 questions. This is -optional and not everyone needs to come, but if there are Midterm 1 topics that -haven't totally clicked yet, this weekend is a perfect time to review them.
- -Everything in this course builds on prior topics, and it's going to be hard to -keep up if you don't have a solid understanding of Midterm 1 material.
- -Remember, it's ok if someone hasn't learned everything yet and needs more time -to master the course material. The whole point of the course is for students to -learn things they don't already know. Please support each other in the process.
- -Ok, time to discuss problems! Remember to work together. Everyone in the group -should understand a solution before the group moves on. Many students find this discussion challenging. Everything gets easier with practice.
+Draw an environment diagram for the code below. You can use paper or a tablet or the whiteboard. Talk to your group about how you are going to draw it, then go through each step together. Then, step through the diagram generated by Python Tutor to check your work.
-VERY IMPORTANT: In this discussion, don't check your answers until your whole group is sure that the answer is right. Figure things out and check your work by thinking about what your code will do. Your goal should be to have all checks pass the first time you run them! If you need help, ask.
- -Implement swipe
, which prints the digits of argument n
, one per line, first backward then forward. The left-most digit is printed only once. Do not use while
or for
or str
. (Use recursion, of course!)
Here's a blank diagram in case you're using a tablet:
- -print
the first line of the output, then make a recursive call, then print
the last line of the output.
-Define the base case for the skip_factorial
function, which returns the product of every other positive integer, starting with n
.
n
is even, then the base case will be 2. If n
is odd, then the base case will be 1. Try to write a condition that handles both possibilities.
-If you have questions, ask them instead of just looking up the answer! First ask your group, and then the course staff.
-Implement is_prime
that takes an integer n
greater than 1. It returns True
-if n
is a prime number and False
otherwise. Try following the approach
-below, but implement it recursively without using a while
(or for
)
-statement.
Remember the problem-solving approach from last discussion; it works just as well for implementing higher-order functions.
-def is_prime(n):
- assert n > 1
- i = 2
- while i < n:
- if n % i == 0:
- return False
- i = i + 1
- return True
+You will need to define another "helper" function (a function that exists just
-to help implement this one). Does it matter whether you define it within
-is_prime
or as a separate function in the global frame? Try to define it to
-take as few arguments as possible.
Implement make_keeper
, which takes a positive integer n
and returns a
+function f
that takes as its argument another one-argument function cond
.
+When f
is called on cond
, it prints out the integers from 1 to n
+(including n
) for which cond
returns a true value when called on each of
+those integers. Each integer is printed on a separate line.
i
and n
evenly divides n
. Then you can call it starting with i=2
:
-
-def is_prime(n):
- def f(i):
- if n % i == 0:
- return ____
- elif ____:
- return ____
- else:
- return f(____)
- return f(2)
-
-Come up with a one sentence docstring for the helper function that describes what it does.
-Don't just write, "it helps implement is_prime
." Instead, describe its
-behavior. When you're done, paste the text of that docstring in your group's
-channel's text
-chat.
Recall the hailstone
function from Homework 1.
-First, pick a positive integer n
as the start. If n
is even, divide it by 2.
-If n
is odd, multiply it by 3 and add 1. Repeat this process until n
is 1.
-Complete this recursive version of hailstone
that prints out the values of the
-sequence and returns the number of steps.
No peeking! First try to implement it without the hint.
+ -