Lab 1: Getting started
Task 0: Review lab policies
There will be an attendance sheet for every lab (except this one!). Make sure you sign the attendance sheet to get credit for attending lab.
It is important that you attend the lab for which you are registered on StudentLink.
If you have a conflict in a given week, you may attend one of the following labs, which have a number of open seats:
- Mon, 6:50-7:40 p.m., EMA 304
- Tues, 6:30-7:20 p.m., EMA 304
- Tues, 6:30-7:20 p.m., CAS 214
However, you should only do this for a good reason, and you should inform the TF of the lab that you attend that you are doing so.
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.
Don’t hesitate to ask for help! The course staff is more than happy to help you with any questions that you may have, and we will be coming around to assist you during lab.
Collaboration. You are encouraged to work with your classmates on the exercises in lab.
You cannot get credit for completing the lab tasks at home and coming to lab only to sign the attendance sheet.
Task 1: Access the necessary software
You are welcome to complete the lab exercises on your own laptop using the software that you installed in Lab 0. If you didn’t bring your laptop with you today, you can also work with another student who did bring one.
If you want to work on one of the machines in EMA 304 or EMA 302, you will need to launch an application called the VMWare Horizon Client. This application will provide a virtual desktop that has all of the necessary software installed. Here are the steps you can use:
Start the VMWare Horizon Client. (If you can’t find it on the Desktop of a machine in EMA 304 or 302, you should be able to search for it from the Windows start menu.)
If you see a cloud icon labeled
casitvdi1.bu.edu, double-click on it.
If you do not see a cloud icon labeled
casitvdi1.bu.edu, click the
+symbol near the top of the window. When asked to enter the name of the Connection Server, type in
casitvdi1.bu.eduand click Connect.
Enter your BU email address in the form
email@example.com your Kerberos password, and click Login.
Double-click on the icon labeled
Computer Science. This should show
you a virtual desktop containing all of the software needed for the labs and problem sets.
Do not store any files directly on the virtual desktop. Instead, you should store files that you want to retain on the
Z:drive that is available from within the virtual desktop. If you do not save your work to the Z: drive, you will not be able to access your work again after you log out!
If you have difficulty installing or running any of the necessary software on your laptop, you can use your own copy of the virtual desktop software, which we asked you to install as part of Lab 0. The necessary instructions are available here.
Task 1: Introduce Piazza
Piazza is the online Q&A site that you should use for questions about any aspect of the course. There is a link for it in the navigation bar of the course website.
Here are some helpful features of Piazza that we would like to emphasize:
- anonymous posts
- private posts
- customizable notifications
- an app available for Android and iOS
- fast response time
Task 2: Explore IDLE
First, start the IDLE program:
If you are using one of the PCs in EMA 304, you can start IDLE by clicking on the icon for it on the virtual desktop.
If you are using your own computer, you should have installed some version of Python 3 as part of Lab 0. If you need help locating the IDLE program on your own computer, ask one of the teaching staff members to help you.
Let’s review the basics of using IDLE. The easiest way to do so is to download a Python file, open it in IDLE, and then run it in IDLE.
Right-click on the following link, and then choose Download File As or Save Link As in order to download the file: lab1task2.py
Save the file. (If you’re using the virtual desktop, save it to the Z: drive.)
In IDLE, choose File->Open... (or use Ctrl + o) and locate the file. (If you’re using the virtual desktop, it will be on the Z: drive.) Double-click on the file (or click Open) to open it in IDLE. This should open up another window on your screen, which we will refer to as the text editor. This is where we can write programs and save them.
From within the text editor, press the F5 key to run the program in the Python Shell (it should execute in the other open IDLE window).
To make it easier to manage the browser (the guide to the lab), the text editor (where you are developing a program), and the Python Shell (where Python runs and displays results) on your computer, we recommend resizing and rearranging the windows in the following way:
This allows you to make the best use of all three windows simultaneously.
Task 3: Understand and debug Python code
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
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.pyfile from Task 2, after all of the existing lines of the program:
print() print('Go Terriers!") print('pi is approximately' (22 / 7)
Make sure that you add the lines to the
lab1task2.pyfile and not to the Python Shell.
Save the changes to the program using Ctrl-S. Then try to run it using F5. What happens?
The new lines include several bugs. See if you can find and fix them. Feel free to ask the TF or CA if you need help.
Task 4: Practice with Scratch
First, start up Scratch:
If you are using one of the PCs in the teaching lab, you can start Scratch by double-clicking on the Scratch 1.4 icon on the virtual desktop.
If you are using your own computer, you should have installed Scratch 1.4 as part of Lab 0. If you need help locating Scratch on your own computer, ask one of the teaching staff members to help you.
(Note: On a Mac, if Scratch does not run after double clicking its icon in your Applications folder, try opening up the Scratch.image file instead, which should be inside of the downloaded Scratch folder.)
The following exercises should help you to become more comfortable working in the Scratch environment, as well as developing simple algorithms to solve problems. Don’t hesitate to ask a staff member if you have a question.
Create a program that works as follows: When the green flag is pressed, the cat should move 50 steps forward, say “Hello!” for one second, and move 50 back to where it started, then turn 90 degrees clockwise. This sequence should be repeated four times, so that the cat ends up where it began when the program is finished.
Save this program as
lab1task4-1using the File->Save menu option.
Start a new program using the File->New menu option. The new program should generate a random number and ask the user to guess it.
The program should work as follows: When the green flag is pressed, a random number should be generated between 1 and 10. You should use a variable to store the random number, which you can select using the
pick randomoperator from the Operators category. (After you create the variable, make sure you uncheck the box next to the variable’s name. This will make sure it doesn’t appear on the stage — we wouldn’t want the user to see the secret number!)
Once the random number is selected, the cat should say, “I’m thinking of a number...” and ask the user for a guess. If the guess is correct, the cat should say, “You win!” Otherwise, the cat should say, “You lose!”.
Save this program as
lab1task4-2using the File->Save menu option.
Use the File->Save As menu option to save a copy of your program for the previous exercise, saving it as
Modify the program so that the user is given three guesses.
After a correct guess, the cat should say, “You win!” as before, and it should stop asking for guesses.
After a wrong guess, the cat should say, “Too high!” if the guess is greater than the random number or “Too low!” if the guess is less than the random number.
If the user does not guess the number after three attempts, the cat should say, “You lose!”.
One way to stop asking for guesses after a correct guess is to use the
stop scriptcommand, both or which are available in the Control category. These commands will stop the program, and thus no further guesses will be requested. However, this approach isn’t ideal, because either
stopcommand will also erase the final “You win!” message.
If time permits, see if you can devise an alternative approach to stopping the guessing that does not use
stop script. Hint: Consider using another variable!
Task 5: Practice submitting work on Gradescope
Ordinarily, we won’t ask you to submit the work that you complete in lab. Rather, there will be an attendance sheet to sign, and staff members will check that you are working steadily on the assigned tasks during the lab.
However, this week we are asking you to submit two of the files from lab:
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.
Here are the steps:
Login to Gradescope by clicking the following link:
If you don’t have a Gradescope account, you should create one now using the link in the email from Gradescope that you should have received on Sunday. If you weren’t registered for the course at that point, or if you can’t find the email from Gradescope, ask your TA or instructor to add you to the course on Gradescope.
Once you are in logged in, click on the box for CS 111. (If you don’t see that box, ask your TA or instructor to add you to the course on Gradescope.)
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 two files (
lab1task4-1.sb) 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 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 to your code. Feel free to ask a staff member for help.
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.
Because your Scratch file has a format that Gradescope can’t read, you won’t be able to view it on the Code page. Instead, you should click on the Download button for your Scratch file to download it. Once you have done so, open the downloaded file in Scratch to ensure that the uploaded file is the correct one.
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.