Part I due by 11:59 p.m. on Sunday, October 19, 2025.
Part II due by 11:59 p.m. on Sunday,October 26, 2025.
In your work on this assignment, make sure to abide by the collaboration policies of the course.
If you have questions while working on this assignment, please
come to office hours, post them on Piazza, or email
cs111-staff@cs.bu.edu.
Make sure to submit your work on Gradescope, following the procedures found at the end of Part I and Part II.
In the rest of this assignment you will design several digital circuits using a circuit-design tool called Logicly. If you haven’t already installed Logicly on your own computer, you should do so now:
(Important: Although it’s possible to use Logicly in your browser, you need to download it in order to be able to save your work.)
That page also includes guidelines for how to use Logicly – including a link to a video that provides a good overview of the program.
Important: There appears to be a bug in Logicly that causes it to occasionally display red wires. If this happens, save your file, close down Logicly, and then reopen it. This will typically fix the problem.
If you can’t get Logicly to work on your own computer, you can use it on the virtual desktop. Instructions for using the virtual desktop can be found here.
Download the following zip file: ps5_circuits.zip
Unzip this archive, and you should find a folder named ps5_circuits, and
within it a starter file for each of the circuit problems.
Warning
In each of the starter files, we have included switches for the inputs and one or more light bulbs for the outputs. You must use the provided components in your circuit, and you should not change their properties (e.g., their names) in any way.
If you fail to use the components that we have provided or if you change them in any way, we will not be able to automate the grading of your submission, and you will lose points as a result.
5 points; individual-only
Open the ps5pr1.logicly starter file in Logicly (see above for how
to obtain the starter files).
The XOR function takes two inputs (x and y), and it outputs a 1
if and only if exactly one of its inputs is 1. It has the following
truth table:
inputs | x y | output ------------------- 0 0 | 0 0 1 | 1 1 0 | 1 1 1 | 0
Build a circuit for the XOR function using the minterm expansion
principle that we discussed in lecture. The resulting circuit should use
only AND, OR, and NOT gates.
Notes:
We’ve provided you with switches for the inputs x and y, as
well as with a NOT gate for the negation of each input. For
example, the leftmost switch is for x itself, and the NOT gate
immediately to its right is for NOT x. We have also provided you
with a light bulb for the output. You must use these
components in your circuit, and you should not change their
properties.
You are welcome to move the provided components as needed, but
please keep their relative positions the same. For example, the
inputs should remain at the top of your circuit, and x should be
to the left of y.
Use the Selection Tool to drag the necessary logic gates into your circuit and to add the necessary wires. See the overview video for more detail.
You may also find it helpful to use the Pan Tool (the icon at the top of the screen that looks like a hand – or possibly a different icon that looks like crossed green arrows) and the magnification slider available in the lower right-hand corner to adjust how much of your circuit is visible. After using the Pan Tool, don’t forget to switch back to the Selection Tool.
Test your circuit by clicking the input switches to turn them on and off. Check to see if you obtain the correct output for all possible inputs. Remember that XOR should output a 1 if and only if exactly one of the two inputs is a 1.
Once this circuit is working, save your work by using the File->Save menu option.
25 points; pair-optional
This is one of only two problems that you may complete with a partner. See the rules for working with a partner on pair-optional problems for details about how this type of collaboration must be structured.
Open the ps5pr2.logicly starter file in Logicly.
If you are working with a partner, there is a text block at the top
of this subcircuit for your partner’s name and email (if any). To add the
necessary information, select the text block with the Selection Tool
(the arrow) and edit the Text in the Label Properties pop-up
window.
Build a Full Adder (FA) as described in lecture, using the minterm
expansion principle to create a circuit that uses only AND, OR,
and NOT gates.
Remember that a Full Adder adds a single column of digits from the bitwise sum of two binary numbers. It takes three inputs:
x and y, the two bits being added from this column of the additionc_in, the carry bit into this column of the additionand it should produce two separate outputs:
s, the bit from the sum that would go at the bottom of this column
of the additionc_out, the carry bit out of this column of the addition.See below for how to export your Full Adder so that it can be used in later problems.
Notes:
After opening the file, you may need to use the Pan Tool (the hand icon available at the top of the screen) and the magnification slider available in the lower right-hand corner to see all of the provided components. After using the Pan Tool, don’t forget to switch back to the Selection Tool.
We’ve provided you with the three inputs and the two outputs, as well
as with NOT gates for the inputs. You must use the provided inputs
and outputs, and you should not change their properties.
You can adjust the positions of the inputs and output as needed, but please keep their relative positions the same.
You should start with the truth table for a Full Adder. You can
write it out yourself, or you can use the one that we gave you
in the lecture notes. Once you have the truth table, you should
apply the minterm expansion principle twice: once to obtain a
circuit that will produce the correct outputs for s, and once to
obtain a circuit that will produce the correct outputs for c_out.
Don’t try to simplify your circuit, and don’t use gates other
than AND, OR, and NOT. The purpose of this problem is to
practice using the minterm expansion principle. (Note: Logicly
provides a sample Full Adder circuit, but it uses an approach other
than minterm expansion, so it’s not useful for this problem.)
Here again, you should test your circuit by clicking the input switches to turn them on and off. Once this circuit is working, save your work by using the File->Save menu option.
Exporting your Full Adder: Because you will use your Full Adder in later problems, you should take the following steps to export it:
Use the Edit->Select All menu option to select the entire circuit.
Click the building block icon (which looks like a Lego piece) at the top of the screen. (Alternatively, you can select the Edit->Create Integrated Circuit menu option.)
In the window that pops up, give your circuit a name (e.g., Full
Adder) by entering it in the Full Name text box. You can also
add a Symbol Label, but doing so is not required.
Click the Create IC button to create the integrated circuit.
Use the File->Export Integrated Circuit Library menu option
to export your work. Give the file an appropriate name (e.g.,
full_adder) and save it in a place where you can easily find it.
15 points; individual-only
Open the ps5pr3.logicly starter file in Logicly.
Build a 4-Bit Ripple-Carry Adder. We examined a 2-Bit Ripple-Carry Adder in lecture; this problem requires you to extend that circuit to a 4-bit version.
Recall that a Ripple-Carry Adder combines multiple Full Adders to produce a circuit that adds two binary numbers. Each Full Adder handles one column of the addition. The circuit as a whole takes eight inputs:
x3, x2, x1, and x0y3, y2, y1, and y0and it should produce five outputs (s4, s3, s2, s1, and s0)
that correspond to the five bits of the sum. The relationships between the
inputs and the outputs are shown below:
x3 x2 x1 x0 + y3 y2 y1 y0 -------------- s4 s3 s2 s1 s0
Note that the sum has five bits to accommodate the possibility of a carry.
This circuit should not be built using the minterm expansion principle. Rather, it should be built by combining four instances of your Full Adder circuit.
See below for information about how to import your Full Adder, as well as for the steps needed to export Ripple-Carry Adder so that it can be used in later problems.
Notes:
Here again, you should use the Pan Tool and the magnification slider as needed to see all of the provided components.
You must use the provided inputs and outputs.
Please keep their relative positions the same, and do not change
their properties. (Note that we haven’t provided NOT gates for the
inputs because you won’t need to negate them.)
Using Your Full Adder:
Custom that contains a building block for your Full Adder.
You will need a c_in of 0 on the far right of the Ripple-Carry
Adder. Use the built-in component labeled Low Constant for this
purpose. Simply drag it into your circuit and connect it to the
appropriate input of the rightmost FA.
Here again, you should test your circuit by clicking the input switches to turn them on and off. Once this circuit is working, save your work by using the File->Save menu option.
Exporting your Work: Because you will use your 4-Bit Ripple Carry Adder in later problems, you should take the following steps to export it:
Use the Edit->Select All menu option to select the entire circuit.
Click the building block icon (which looks like a Lego piece) at the top of the screen. (Alternatively, you can select the Edit->Create Integrated Circuit menu option.)
In the window that pops up, give your circuit a name (e.g., 4-Bit
Ripple-Carry Adder) by entering it in the Full Name text
box. You can also add a Symbol Label, but doing so is not
required.
Click the Create IC button to create the integrated circuit.
Use the File->Export Integrated Circuit Library menu option to
export your work. Note that you will end up exporting both your
Full Adder (since you imported it for this problem) and your
Ripple-Carry Adder. Give the file an appropriate name (e.g.,
both_adders) and save it in a place where you can easily find it.
Important
Make sure that you do not have any imported components that you are not actually using in your circuit. Such components will cause an error in Gradescope.
To check for this, open your circuit in Logicly and scroll down to the Custom section of the left-hand component bar. For each component in the Custom section, right click on it and choose “Delete Integrated Circuit.” If the component is actually being used in your circuit, Logicly will display a message indicating that the component cannot be deleted. If the component is not being used, Logicly will allow you to delete it.
10 points; individual-only
Open the ps5pr4.logicly starter file in Logicly.
Build a 4x1 multiplier in the space provided. This circuit takes five inputs:
x3, x2, x1, and x0y.It will have four outputs (p3, p2, p1, and p0) that correspond to
the four bits of the product. The relationships between the
inputs and the outputs are shown below:
x3 x2 x1 x0 * y -------------- p3 p2 p1 p0
Because you are multiplying the first factor by either 0 or 1, the product can be computed very simply, using exactly four gates! Considering some concrete cases should help you to determine which gates you should use, and how they should be arranged. You should not need to employ the minterm expansion principle.
Notes:
Here again, you should use the Pan Tool and the magnification slider as needed to see all of the provided components.
You must use the provided inputs and outputs, and you must not change their properties. Please keep their relative positions the same.
We’ve positioned the outputs at the bottom of the circuit, because doing so will make your circuit easier to use in the context of the next problem. Because of this, you may want to adjust the directions in which your gates are facing. After adding a gate to the circuit, you can rotate it by selecting it and then using one of the rotate icons at the top of the screen.
As always, you should test your circuit by clicking the input switches to turn them on and off. Once this circuit is working, save your work by using the File->Save menu option.
Exporting your 4x1 Multiplier: Because you will use your 4x1 Multiplier in the next problem, you should take the following steps to export it:
Use the Edit->Select All menu option to select the entire circuit.
Click the building block icon (which looks like a Lego piece) at the top of the screen. (Alternatively, you can select the Edit->Create Integrated Circuit menu option.)
In the window that pops up, give your circuit a name (e.g.,
4x1 Multiplier) by entering it in the Full Name text
box. You can also add a Symbol Label, but doing so is not
required.
Click the Create IC button to create the integrated circuit.
Use the File->Export Integrated Circuit Library menu option
to export your work. Give the file an appropriate name (e.g.,
4x1_multiplier) and save it in a place where you can easily
find it.
15 points; individual-only
Open the ps5pr5.logicly starter file in Logicly.
Build a 4x2 multiplier, which takes six inputs:
x3, x2, x1, and x0y1 and y0.and produces as outputs the six bits of the product: p5, p4, p3,
p2, p1, and p0.
Your circuit should perform the computation shown below:
x3 x2 x1 x0 * y1 y0 ----------------- p5 p4 p3 p2 p1 p0
You circuit should employ the “elementary-school” binary multiplication
algorithm that we discussed in lecture. More specifically, you need to
compute two partial products: the product of the top number
(x3 x2 x1 x0) with the bit y0, and the product of the top number
with the bit y1. You then need to add these partial products together
in the appropriate way.
This circuit should not be built using the minterm expansion principle. Rather, it should be built by combining one or more instances of your 4x1 Multiplier and your 4-Bit Ripple-Carry Adder. See below for information about adding those components to your circuit.
Notes:
Here again, you should use the Pan Tool and the magnification slider as needed to see all of the provided components.
You must use the provided inputs and outputs, and you must not change their properties. Please keep their relative positions the same.
You can insert one or more copies of your 4x1 Multiplier and 4-Bit Ripple-Carry Adder using the same procedure that you used to add instances of your Full Adder in Problem 3. In this case, you will need to import two files: the one containing both adders (i.e., your work from Problem 3), and the one containing your 4x1 Multiplier (i.e., your work from Problem 4).
We recommend that you rotate each 4x1 Multiplier and 4-Bit Ripple-Carry Adder clockwise, following the procedure used to rotate your Full Adder in Problem 3. Doing so will cause each component’s inputs to be at the top of its box, and its outputs to be at the bottom of its box.
You will need at least one constant in your circuit. See the notes that accompany Problem 3 for a reminder of how to add a constant.
Don’t forget to test your circuit and save your work! During testing, you may find it helpful to use a calculator that can multiply in binary. Here are three options:
In Windows 10 or later, open the Calculator by searching for it from the Start menu. Then use the Programmer menu option, and choose the BIN option near the left-hand side of the window.
In older versions of Windows, open the Calculator by going to Start Menu->Accessories->Calculator. Then use the View->Programmer menu option, and choose the Bin option on the left-hand side of the window.
In Mac OS X, open the Calculator from /Applications, Spotlight, or Launchpad. Then select the View->Programmer menu option.
Write a function in Python that makes use of the base-conversion functions that you wrote for Problem Set 4!
Important
See our warning at the end of Problem 3 about unused imported components. Make sure to delete any unused components before you submit your work.
Login to Gradescope by clicking the link in the left-hand navigation bar, and click on the box for CS 111.
You should only submit the following files:
ps5pr1.logiclyps5pr2.logiclyps5pr3.logiclyps5pr4.logiclyps5pr5.logiclyYou do NOT need to submit the files that Logicly produces when you export your components.
Here are the steps:
Click on the name of the assignment in the list of assignments. You should see a pop-up window with a box labeled DRAG & DROP. (If you don’t see it, click the Submit or Resubmit button at the bottom of the page.)
Add your files to the box labeled DRAG & DROP. You can either drag and drop the files from their folder into the box, or you can click on the box itself and browse for the files.
Click the Upload button.
You should see a box saying that your submission was successful.
Click the (x) button to close that box.
The Autograder will perform some tests on your files. Once it is done, check the results to ensure that the tests were passed. If one or more of the tests did not pass, the name of that test will be in red, and there should be a message describing the failure. Based on those messages, make any necessary changes. Feel free to ask a staff member for help.
Note: You will not see a complete Autograder score when you submit. That is because additional tests for at least some of the problems will be run later, after the final deadline for the submission has passed. For such problems, it is important to realize that passing all of the initial tests does not necessarily mean that you will ultimately get full credit on the problem. You should always run your own tests to convince yourself that the logic of your solutions is correct.
If needed, use the Resubmit button at the bottom of the page to resubmit your work. Important: Every time that you make a submission, you should submit all of the files for that Gradescope assignment, even if some of them have not changed since your last submission.
Because your Logicly files have a format that Gradescope can’t read, you won’t be able to view those files on the Code page. Instead, you should click on the Download button for each Logicly file to download it. Once you have done so, open the downloaded file in Logicly to ensure that the uploaded file is the correct one.
Important
It is your responsibility to ensure that the correct version of every file is on Gradescope before the final deadline. We will not accept any file after the submission window for a given assignment has closed, so please check your submissions carefully using the steps outlined above.
If you are unable to access Gradescope and there is enough
time to do so, wait an hour or two and then try again. If you
are unable to submit and it is close to the deadline, email
your homework before the deadline to
cs111-staff@cs.bu.edu
Problems 6 and 7 will be completed in a single PDF file. To create it, you should do the following:
Make sure you are signed into your Google Drive account. Note that signing into BU Google Mail should accomplish the same thing.
Access the template that we have created by clicking on this link.
When asked, click on the Make a copy button, which will save a copy of the template file to your Google Drive.
Select File->Rename, and change the name of the file to
ps5pr67.
Add your work for Problems 6 and 7 to this file.
Once you have completed these problems, choose
File->Download->PDF document, and save the PDF file on your machine.
The resulting PDF file (ps5pr67.pdf) is the one that you will
submit. See the submission guidelines at the end of Part II.
range function6 points; individual-only
As we saw earlier in the semester, range() is a built-in
function that can be used to generate a sequence of integers.
This function is often used in conjunction with for loops in
Python, so it’s important that you fully understand how it works.
Put your answers to the following questions in the Problem 6
section of ps5pr67.
What results do you obtain when you evaluate each of the following
expressions in the console? (Note: In order to see the
sequence that the range function generates, you need to use the
list function, as shown below.)
a. list(range(3))
b. list(range(10))
c. list(range(5, 10))
d. list(range(10, 20))
e. list(range(0, 10, 3))
f. list(range(10, 0, -2))
The for loops below use an explicit list of numbers (e.g.,
[0, 1, 2, 3, 4]). Let’s say that we want to replace these
explicit lists with expressions involving the range()
function. What range()-function expression would be needed in
each case? (Note: You do not need to include the list
function in this case, because we only need the appropriate
range expression to generate the necessary sequence of integers.)
a. first for statement:
for x in [0, 1, 2, 3, 4]: print(x)
b. second for statement:
for x in [3, 4, 5, 6]: print(x)
c. third for statement:
for x in [20, 17, 14, 11]: print(x)
10 points; individual-only
Consider the following Python function, which uses an
index-based for loop:
def mystery(values): count = 0 for i in range(len(values)): if values[i] > values[i-1]: count += 1 return count
Trace the execution of the following call to this function:
mystery([8, 5, 3, 7, 1, 6])
To do so, use the template that we have provided in
section 7-1 of ps5pr67. In particular, you should:
Complete the table to illustrate how the expression at the top of each column changes during the execution of the loop.
The table begins with a row for the initial value of the
variable count. Use the remaining rows to show what happens
for each value of the loop variable i. You may not need all
of the rows.
Specify the return value of this function call in the space provided.
Consider the following Python program, which uses a while loop:
a = 12 b = 4 print(a, b) while a > 2: a -= b b -= 1 print(a - b)
Complete the table that we have provided in section 7-2 of
ps5pr67 to show how the variables change over time and the
values that are printed. You may not need all of the rows.
30 points; pair-optional
This is one of only two problems in this assignment that you may complete with a partner. See the rules for working with a partner on pair-optional problems for details about how this type of collaboration must be structured.
Getting started
If you haven’t already done so, create a folder named ps5 for
your work on this part of the assignment. You can find
instructions for doing so here.
In Spyder, open a new editor window using File -> New File,
and save it to your ps5 folder using the name ps5pr8.py.
Important guidelines
Here are the guidelines that you should follow for this and all remaining Python problems over the course of the semester:
Include comments at the top of the file
that are similar to the ones that we gave you at the top of
ps1pr3.py.
Your functions must have the exact names specified below,
or we won’t be able to test them. Note in particular that the
case of the letters matters (all of them should be lowercase),
and that some of the names include an underscore character (_).
As usual, each of your functions should include a docstring that describes what your function does and what its inputs are. In addition, you should include any other comments that might be necessary to explain your code. More generally, you should aim to make your code easy to read. For example, you should choose descriptive names for your variables. In addition, we encourage you to leave a blank line between logical parts of your function.
If a function is supposed to return a value, make sure that it actually returns the specified value, rather than printing it.
You should not use any Python features that we have not discussed in lecture.
Your functions do not need to handle bad inputs – inputs with a type or value that doesn’t correspond to the description of the inputs provided in the problem – unless the problem explicitly states otherwise.
Leave one or two blank lines between functions to make things more readable.
If you want to add test calls to this or any other Python file,
please do so in appropriate test function like the one that we
gave you at the bottom of the
ps1pr3.py starter file for Problem
Set 1. After running your Python file, you can call the
test function (by entering test()) to see the results of
all of the test calls.
Do not add any lines of code that belong to the global scope of the program (i.e., lines that are outside of any function).
Write a function cube_all(values) that takes as input a list
of numbers called values, and that uses a loop to create
and return a list containing the cubes of the numbers in
values (i.e., the numbers raised to the third power). For
example:
>>> cube_all([-2, 5, 4, -3]) result: [-8, 125, 64, -27] >>> cube_all([1, 2, 3]) result: [1, 8, 27]
You solved a somewhat similar problem in Problem Set 3 using a list comprehension and then again using recursion, but for this problem set you must use a loop. You may not use recursion or a list comprehension.
Here is a template that you can use to get started:
def cube_all(vals): """ your docstring goes here """ result = [] for ____ in ______: ...
Hint: This function should perform a cumulative computation that gradually builds up a list.
Write a function add_stars(s) that takes a string s of one or
more characters and uses a loop to create and
return the string formed by adding a “star” (i.e., an asterisk
character '*') between each pair of adjacent characters in s.
For example:
>>> add_stars('hello') result: 'h*e*l*l*o' >>> add_stars('hangman') result: 'h*a*n*g*m*a*n' >>> add_stars('x') result: 'x'
Your solution must use a loop. It may not use recursion or a list comprehension.
Here is a template that you can use to get started:
def add_stars(s): """ your docstring goes here """ result = '' for ____ in ______: ...
Hints:
This function should perform a cumulative computation that
gradually builds up a string. We discussed a similar function
(a loop-based remove_vowels) in lecture.
You will need to ensure that no stars are added to the
beginning or end of the returned string. There are different
ways of doing so. One option is to write a loop that processes the
entire string s and to then remove any unwanted stars before
returning the result. Another option is to write a loop that
only processes a portion of s and to then add one or more
characters from s to the result before returning it.
Write a function compare(s1, s2) that takes as inputs two
arbitrary strings s1 and s2 and uses a loop to determine
and return the number of differences between the two strings
– i.e., the number of positions at which s1 and s2 have
different characters. If one of the strings is longer than the
other, the number of extra characters in the longer string should
be included in the final result. For example:
>>> compare('alien', 'allen') # only position 2 is different result: 1 >>> compare('alien', 'alone') # positions 2, 3, and 4 all differ result: 3 >>> compare('aliens', 'alone') # positions 2, 3, and 4, plus the extra character at the end of aliens result: 4
Your solution must use a loop. It may not use recursion or a list comprehension.
Hints:
You will need to use an index-based loop so that you can
access the corresponding characters from both s1 and s2 at
the same time. Here is a template that you can use to get
started:
def compare(s1, s2): """ your docstring goes here """ result = 0 len_shorter = min(len(s1), len(s2)) for i in range(len_shorter): ...
Note that we determine the length of the shorter string before beginning the loop, because the loop should only consider the index values that are present in both strings.
After the loop, you will need to include in the result a count
of any “extra” characters from the longer string (for cases in
which the strings don’t have the same length). One way to do
that is to use conditional execution (e.g., an if-else
statement), although other approaches may also be possible.
Write a function weave(vals1, vals2) that takes as inputs two
lists vals1 and vals2 and uses a loop to construct
and return a new list that is formed by “weaving” together
the elements in the lists vals1 and vals2 to create a single
list. The new list should alternate elements from the two lists:
the first element from vals1, followed by the first element from
vals2, followed by the second element from vals1, followed by
the second element from vals2, etc. For example:
>>> weave([1, 1, 1], [2, 2, 2]) result: [1, 2, 1, 2, 1, 2] >>> weave([3, 4, 5, 6], [7, 8, 9, 0]) result: [3, 7, 4, 8, 5, 9, 6, 0]
If one of the lists is longer than the other, its “extra” elements – the ones with no counterparts in the shorter list – should appear immediately after the “woven” elements (if any) in the new list. For example:
>>> weave([0, 0, 0, 0], [1, 1]) # two extra elements in first list result: [0, 1, 0, 1, 0, 0] >>> weave([2, 1, 0], [3, 4, 5, 6]) # one extra element in second list result: [2, 3, 1, 4, 0, 5, 6]) >>> weave([1, 2], []) # all of the first list's values are extra! result: [1, 2] >>> weave([], [3, 4, 5]) # all of the second list's values are extra! result: [3, 4, 5] >>> weave([], []) result: []
Your solution must use a loop. It may not use recursion or a list comprehension.
14 points; individual-only
In Spyder, open a new editor window for your code, and save it to
your ps5 folder using the name ps5pr9.py.
This problem is designed to give you practice in selecting the correct type of loop for a given problem.
Important
One of the functions must use a for loop, and
one must use a while loop. You will need to
decide which loop construct is the appropriate one for each
function. Think about whether each function is better suited to a
definite loop or an indefinite loop.
You should continue to follow the guidelines that we gave you in the previous problem.
Here again, any test calls should go in an appropriate test function. Do not add any lines of code that belong to the global scope of the program (i.e., lines that are outside of any function).
Write a function add_odds(n) that takes a non-negative integer
n and that uses a loop to compute and return the sum of
the first n positive odd integers.
In addition, the function should print a sequence of messages that show how the sum is gradually built up. For example:
For example:
>>> add_odds(5) 0 + 1 = 1 1 + 3 = 4 4 + 5 = 9 9 + 7 = 16 16 + 9 = 25 result: 25
Notes/hints:
The final line shown above displays the return value of the function. The function should not actually print this line; it should just return the appropriate value.
The function should use either a for loop or a while
loop. You should decide which loop construct is the better
one for this function, based on whether its task lends itself
better to a definite loop or an indefinite loop.
You will need two accumulator variables:
one for the current odd number.
one for the sum of the odd numbers, which is the value that you will ultimately return.
Don’t forget to initialize these variables before the start of the loop, and to update them within the loop. Note that you can get from the current odd number to the next odd number by adding 2!
You may also find it helpful to use one or more additional variables.
Here are some other examples:
>>> add_odds(3) 0 + 1 = 1 1 + 3 = 4 4 + 5 = 9 result: 9 >>> add_odds(7) 0 + 1 = 1 1 + 3 = 4 4 + 5 = 9 9 + 7 = 16 16 + 9 = 25 25 + 11 = 36 36 + 13 = 49 result: 49 >>> add_odds(0) result: 0
Write a function get_mult(n) that takes a positive integer n
and that uses a loop to obtain a multiple of n from the user. More
specifically, the function should perform the following tasks:
Get an initial integer value from the user using the input
function and the prompt
Enter a multiple:
If the user does not enter a multiple of n, keep asking
for additional inputs until the user enters an appropriate value.
These additional inputs (if any) should use the following prompt:
Invalid input. Try again:
Once the user enters a multiple of n, return the value.
You may assume that the user always enters an integer.
For example:
>>> get_mult(3) Enter a multiple: 5 Invalid input. Try again: 10 Invalid input. Try again: 12 result: 12
Notes/hints:
The final line shown above displays the return value of the function. The function should not actually print this line; it should just return the appropriate value.
The function should use either a for loop or a while
loop. You should decide which loop construct is the better
one for this function, based on whether its task lends itself
better to a definite loop or an indefinite loop.
Don’t forget that input always returns a string. As a result,
you will need to use the int function to convert the input
to an integer as discussed in lecture.
Important
If you made the correct choice of loop for both functions in this
problem, one of them should have used a for loop and one should
have used a while loop.
Login to Gradescope by clicking the link in the left-hand navigation bar, and click on the box for CS 111.
You will make submissions to two separate assignments on Gradescope. The steps needed for the two submissions are different, so please make sure to follow carefully the procedures outlined below.
PS 5: Problems 6 and 7
Submit your ps5pr67.pdf file using these steps:
If you still need to create a PDF file, open your file on Google Drive, choose File->Download->PDF document, and save the PDF file on your machine.
Click on the name of the assignment in the list of assignments on Gradescope. You should see a pop-up window labeled Submit Assignment. (If you don’t see it, click the Submit or Resubmit button at the bottom of the page.)
Click the Select PDF button and find the PDF file that you created. Then click the Upload PDF button.
You should see a question outline along with thumbnails of the pages from your uploaded PDF. For each question in the outline:
As you do so, click on the magnifying glass icon for each page and doublecheck that the pages that you see contain the work that you want us to grade.
Once you have assigned pages to all of the problems in the question outline, click the Submit button in the lower-right corner of the window. You should see a box saying that your submission was successful.
If needed, use the Resubmit button at the bottom of the page to resubmit your work.
PS 5: Problems 8 and 9
Submit your ps5pr8.py and ps5pr9.py files using these steps:
Click on the name of the assignment in the list of assignments. You should see a pop-up window with a box labeled DRAG & DROP. (If you don’t see it, click the Submit or Resubmit button at the bottom of the page.)
Add your files to the box labeled DRAG & DROP. You can either drag and drop the files from their folder into the box, or you can click on the box itself and browse for the files.
Click the Upload button.
You should see a box saying that your submission was successful.
Click the (x) button to close that box.
The Autograder will perform some tests on your files. Once it is done, check the results to ensure that the tests were passed. If one or more of the tests did not pass, the name of that test will be in red, and there should be a message describing the failure. Based on those messages, make any necessary changes. Feel free to ask a staff member for help.
Note: You will not see a complete Autograder score when you submit. That is because additional tests for at least some of the problems will be run later, after the final deadline for the submission has passed. For such problems, it is important to realize that passing all of the initial tests does not necessarily mean that you will ultimately get full credit on the problem. You should always run your own tests to convince yourself that the logic of your solutions is correct.
If needed, use the Resubmit button at the bottom of the page to resubmit your work. Important: Every time that you make a submission, you should submit all of the files for that Gradescope assignment, even if some of them have not changed since your last submission.
Near the top of the page, click on the box labeled Code. Then click on the name of each file to view its contents. Check to make sure that the files contain the code that you want us to grade.
Important
It is your responsibility to ensure that the correct version of every file is on Gradescope before the final deadline. We will not accept any file after the submission window for a given assignment has closed, so please check your submissions carefully using the steps outlined above.
If you are unable to access Gradescope and there is enough
time to do so, wait an hour or two and then try again. If you
are unable to submit and it is close to the deadline, email
your homework before the deadline to
cs111-staff@cs.bu.edu
Last updated on October 22, 2025.