Every lab section has two staff members: a teaching assistant (TA) and an undergrad course assistant (CA). They and the entire course staff are looking forward to working with you in labs and office hours.
You should have already installed the necessary software on your own laptop following the instructions in Lab 0.
If you can’t get any of the required software to work on your own computer, you can use it on the virtual desktop. Instructions for doing so can be found here.
If you have any questions about this lab or anything else regarding the course, you can post them on Piazza, our course’s Q&A site. Use the link in the left-hand navigation bar to access Piazza.
Piazza allows both staff and students to respond to questions, so we encourage you to reply to another student’s question when you feel able to do so. In addition to helping others, answering questions is a great way to reinforce your own understanding of a given topic!
Piazza also has:
anonymous posts, so that only the course staff will see the name of the person who posted it, although everyone will see the question itself
private posts, which only the course staff will see. These shouldn’t be used too often, since it’s better if other students can see and benefit from your question and the subsequent answers. However, a private post can be useful if you feel like you need to show us a small piece of your code as part of your question.
a search feature. Before posting a question on Piazza, you should use this feature to see if someone else has already asked a similar question!
apps for Android and iOS.
The labs consist of practice exercises that are designed to reinforce the key concepts from lecture and to prepare you for the problem sets.
Feel free to ask questions at any point during the lab.
We may not finish all of the lab exercises during the actual lab session. Every Wednesday, we will post solutions to the current week’s lab on the Labs page of the course website.
We don’t grade the lab exercises. However, starting with next week’s lab, your attendance at lab will count towards your participation grade. If you attend 85% of the lab sessions over the course of the semester, you will get full credit for lab participation. See the syllabus for more details.
To get full credit for participation in lab, you must work productively throughout the lab session. You will not be penalized if you cannot finish all of the lab exercises.
Feel free to work on the lab exercises with your classmates, and don’t hesitate to ask a staff member for help!
Creating folders on your laptop is a great way to organize your work. It is also essential to certain programming tasks.
First, create a folder named cs111
on your Desktop.
On Windows:
Right-click on the Desktop.
Choose New -> Folder.
Enter a name for the folder, then press Enter.
On macOS:
Click on the Desktop.
Choose File -> New Folder.
Enter a name for the folder, then press Return.
Double-click on the newly created folder to open it.
Create a subfolder named lab1
within your cs111
folder. You
should be able to use similar steps to the ones listed above,
except that you would start by right-clicking/clicking on the
inside of the cs111
folder.
If you have trouble creating these folders, feel free to ask a staff member for help.
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.
Using Spyder
Let’s review the basics of using Spyder. The easiest way to do so is to
download a Python file, open it in Spyder, and then run it in Spyder.
Click on the following link: lab1task2.py
Save the file in the lab1
folder that you created above.
Note: 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.
To run the 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:
congratulations on taking CS 111 maybe you will take CS 112 next semester the first midterm is in fewer than 40 days that is approximately 5 weeks
Let’s take another look at the program from Task 2.
Give a step-by-step description of what happens when the following two statements are executed:
course = course + 1 print('maybe you will take CS', course, 'next semester')
Consider the following two lines of the program:
weeks = days // 7 print('that is approximately', weeks, 'weeks')
What is the difference between weeks
and 'weeks'
?
Why does the program print 5 weeks instead of 6 or 5.7142857...?
How could we make the program print a more precise result for the number of weeks?
Copy and paste the following lines of buggy code into your
lab1task2.py
file in the Editor pane, after all of the existing
lines of the program:
print() print('Go Terriers!") print('pi is approximately' (22 / 7)
Try to run the modified program. What happens?
The new lines include several bugs. Note that Spyder puts a special warning icon next to the line number of the first line in the program that has a bug. (There may also be other buggy lines later on in the program, but they won’t be revealed until the earlier lines are fixed.)
See if you can find and fix all of the bugs.
Once all of the bugs on a given line have been removed, its warning icon should disappear.
Keep going until there are no more warning icons, and the program runs correctly – without any error messages showing up in the console, and with the desired output being printed.
Once the program is working, make sure to save the final version of the program as needed 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.)
Consider the following program:
a = 4 b = 14 c = b // a d = b / a e = b % 6 b = b + 2 a = 'e' print(a, b, c, d, e) print(b + c, 'b')
To begin, 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
lab1task4
.
The template includes a table that you should fill in to show how the values of the variables change over time.
Using a table in this way is a great way to determine what a program is doing.
Based on your tracing, what is the output of this program?
Next, let’s see how we can use an online tool called Python Tutor to help us in tracing through a program.
Ordinarily, we won’t ask you to submit the work that you complete in lab.
However, this week we are asking you to submit your lab1task2.py
file.
Doing so will allow you to practice the process of submitting files on Gradescope, which is the site that we will be using for submissions and grading throughout the semester. We won’t actually grade the work that you submit for this lab.
Here are the 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 in logged in, click on the box for CS 111. (If you
don’t see that box, you should ask your TA to add you to the
the course on Gradescope, or you can email cs111-staff@cs.bu.edu
to request that you be added.)
Click on the name Lab 1 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 file (lab1task2.py
) to the box labeled DRAG &
DROP. You can either drag and drop the files from their folder
into that 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 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 to your code.
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, 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 lab1task2.py
, which should show you
the contents of that file.
Important
On the problem sets, it will be your responsibility to ensure that the correct version of each file is on Gradescope before the deadline, and that any preliminary Autograder tests have been passed. We will not accept any file after the submission window for a given assignment has closed, so please check every submission carefully using steps like the ones outlined above.
Last updated on September 9, 2024.