due by 11:59 p.m. on Sunday, February 2, 2025
In your work on this assignment, make sure to abide by the collaboration policies of the course.
Lab 0
If you haven’t already done so, you should complete Lab 0 ASAP.
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 the assignment.
If you haven’t already created a folder named cs111
for your
work in this course, follow these
instructions to do so.
Then create a subfolder called ps0
within your cs111
folder,
and put all of the files for this assignment in that folder.
Problems 0 and 1 will both be completed in a single text file. To create it, you should do the following:
Access the template that we have created by clicking on this link and signing into your Google account as needed.
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
ps0pr01
.
Add your work for Problems 0 and 1 to this file.
Once you have completed both of these problems, choose
File->Download->PDF document, and save the file in your ps0
folder (see above). The resulting PDF file (ps0pr01.pdf
) is the one
that you will submit. See the submission guidelines at the end of the
assignment.
5 points; individual-only
Each week, problem 0 will involve reading a short article and writing a brief response. The readings may not relate directly to the topics from lecture, but our hope is that they will allow you to explore some of the many real-world aspects of computer science.
This week’s reading highlights research that has been done right here at BU! Prof. Emily Whiting and her colleagues have worked to develop ways to make it easier for people without a technical background to use complex design software. In the project that you’ll read about, they made it possible for users to create intricate watercolor paintings using a simple computer program.
The article is available here: Taking the Pain out of Painting
(If you can’t access that page, you can find a PDF version of the article here.)
(If you’re interested in learning more about Prof. Whiting’s work, you can explore her research group’s site.)
After reading the article, write a response that answers the following question: What was the most interesting or important idea in this article for you – and why?
Important: Put your response in the copy of the ps0pr01
template that you created on Google Drive (see above).
20 points; individual-only
Note: The template for Problem 1 begins at the top of the
second page of ps0pr01
. To facilitate grading, please ensure
that all of your work for this problem stays on a single page.
Consider the following Python program:
x = 14 y = 3 y = y * 10 z = y - x x = x // 5 y = z % 3
In section 1-1 of ps0pr01
, we have given you a table in which we
have begun a trace of the program. Fill in the rest of the table
to show how the values of the variables change over the course of
the program.
Assume that you have two variables a
and b
that have
each been assigned an integer value. Construct the assignment
statements and expressions specified below.
Important: Assignment statements should assign a
value to a variable using the assignment operator (=
).
Expressions should not assign anything.
Sample assignment statements include:
a = b * 2
b = b + 1
a = a + 2
Sample expressions include:
a + 3
a - b
Here are your tasks:
Write an assignment statement that adds 7 to the current value
of a
and assigns the result back to a
.
Write an expression that computes the value that is twice
the value of b
.
Write an assignment statement that gives b
the value
that is one-third of the value of a
. Use the division operator
that gives the more precise result.
Write an expression that raises a
to the b
th power.
Assume that you have two variables s
and t
that have
each been assigned a string value. Construct the assignment
statements and expressions specified below.
Write an expression that extracts a slice consisting of
the first 3 characters of s
.
Write an assignment statement that concatenates the string
'ing'
to the end of the current value of t
and assigns the
result back to t
.
Write an assignment statement that replaces the current value of
s
with the last (i.e., rightmost) character of t
.
Write an expression that produces a string consisting of the
characters in the current value of s
, but in reverse
order. For example, if s
represents the string 'hello'
,
the expression should produce the string 'olleh'
. Hint:
Use skip-slicing!
Once you have completed Problems 0 and 1, choose File->Download->PDF
document, and save the PDF file in your ps0
folder (see above).
The resulting PDF file (ps1pr01.pdf
) is the one that you will
submit. See the submission guidelines at the end of the assignment.
25 points; pair-optional
This is the only problem of the 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.
Configuring and using Spyder
As needed, you should review this page, which explains how to start and configure Spyder. Please make sure that you configure Spyder correctly before you continue.
In this problem you will write a simple Python program that computes the integers 0 through 4 using expressions involving exactly four fours and no other numbers. For example:
zero = 4 + 4 - 4 - 4
Here are the steps you must take:
If you haven’t already done so, create a folder named ps0
for your work on this assignment. You can find instructions for
doing so here.
Download the following file: ps0pr2.py
Make sure to put the file in your ps0
folder. If your
browser doesn’t allow you to specify where the file should be
saved, try right-clicking on the link and choosing Save as... or
Save link as..., which should produce a dialog box that allows
you to choose the correct folder for the file.
In Spyder, choose the File->Open... menu option and locate the file. Double-click on the file to open it in Spyder. This should add a tab for the file to your Editor pane.
Note that the current version of the program includes the line
above, which uses four 4s to compute 0 and assigns the
result to a variable named zero
. It also includes some code at
the bottom of the file that will allow you to test the values of
your expressions. You should not make any changes to that test
code.
Below the line that we’ve given you for zero
, add a line of
code that computes the integer 1 using four 4s and assigns
the resulting value to a variable named one
.
Important notes
Your expressions may use any of the following operators: +
,
-
, *
, //
(integer division), **
(power), and
parentheses. Your expressions may not use anything else
except these operators and the numeral 4
.
You should use the integer division operator (//
) instead of
the regular division operator (/
), because the /
operator
will cause your results to include a decimal. For example,
4//4
will give you 1
, but 4/4
will give you 1.0
.
We recommend using the IPython console on the right side of
Spyder to test out various expressions involving four fours.
For example, to test out the expression we’ve given you for
zero
, you could simply enter it at the input prompt in the
IPython console:
>>> 4 + 4 - 4 - 4 result: 0
Then, once you find an expression that works for a given value, you can assign it to the appropriate variable in your program.
There are multiple ways to use four 4s compute a given integer. For example, here’s an alternative approach for 0:
zero = 4//4 - 4//4
Next, add a line of code that computes the integer 2 using four
4s and assigns the resulting value to a variable named two
.
Next, add a line of code that computes the integer 3 using four
4s and assigns the resulting value to a variable named three
.
Finally, add a line of code that computes the integer 4 using four
4s and assigns the resulting value to a variable named four
.
To test your entire program, click the green “play” icon that should be available near the top of the Spyder window. (Alternately, you can use Run->Run or the F5 key.) If you see a Run settings pop-up window, you can just click the Run button at the bottom of that window.
The output of the program should be displayed in the IPython console on the right of the Spyder window. First you will see a line that specifies what file is being run, and then you will see the program’s output, which should look like this:
zero = 0 one = 1 two = 2 three = 3 four = 4
Once your program is working, make sure to save the final version of the program using Ctrl-S or the File-Save menu option. There is also a small “disk” icon near the top of the Spyder window that you can use for this purpose. (Note that running the program will also save it, so you may not need to explicitly save it you haven’t made any changes since you ran it.)
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 0: Problems 0 and 1
Submit your ps0pr01.pdf
file using these steps:
Login to Gradescope by clicking the link in the left-hand navigation bar. When logging in, make sure that you use the School Credentials option and select Boston University.
Once you are logged in, click on the box for CS 111. (If you
don’t see that box, you should email cs111-staff@cs.bu.edu
so
that we can add you to the course’s Gradescope site.)
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 in your ps0
folder.
Click on the name of the assignment (PS 0: Problems 0 and 1) 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.)
Choose the Submit PDF option, and then 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.
PS 0: Problem 2
Submit your ps0pr2.py
file using these steps:
Click on the name of the assignment (PS 0: Problem 2) in the list of assignments on Gradescope. 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 the file to the box labeled DRAG & DROP. You can either drag and drop the file from its folder into the box, or you can click on the box itself and browse for the file.
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 file. 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 will be run later, after the final deadline for the submission has passed. As a result, 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 and that you have satisfied all of the stated requirements.
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 your file as needed to view its contents. Check to make sure that the file contains 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 April 28, 2025.