Lab 1: Getting started
Task 0: Review lab policies
Structure. Lab will typically begin with a brief lecture or example by the teaching fellow, followed by a chance for the class to ask questions. After that, there will be a series of exercises for you to complete.
For every lab (except for the first lab), there will be an attendance sheet. 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. In addition, it is important that your lab comes after your first lecture for the week. In particular, students in the C1 lecture should not be enrolled in a lab that meets before the Tuesday lecture. If you are in an incorrect lab, or if you are not enrolled in any lab, please notify your lecture instructor.
To get full credit for participation in lab, you must work productively and submit the work that you complete. 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: Introduce Piazza
Piazza is an educational social network designed to facilitate communication between students, teaching assistants, and instructors. If you haven’t set up an account yet, do that now. If you have set up an account, go ahead and log in. In either case, you should use the Piazza link in the navigation bar of the course website.
There 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 the teaching lab, you can start IDLE by clicking on the Windows icon in the lower-left corner, finding the folder Python 3.7, and clicking IDLE (Python 3.7 32-bit) from that folder.
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 a lab computer, save it to the Z: drive.)
In IDLE, choose File->Open... (or use Ctrl + o) and locate the file. (If you’re using a lab computer, 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).
When working on a machine in EMA 304 or EMA 302, you should save all of your work on the Z: drive. This is a special directory maintained by the computer science department which is accessible from any computer to which you are logged on using your CS account (either in the teaching lab or in the undergraduate lab). 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!
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
Open up a text editor (Notepad or TextEdit) and create a text file named lab1task3.txt. Put all answers that you write for this task in this file. (On the lab machines, Notepad is available by clicking on the Windows icon and going to the Windows Accessories folder.)
The text files that you submit for this course must be plain-text files. More information about what this means is available here. Please read the information on that page carefully before you proceed.
Let’s take another look at the program from Task 2.
Explain in detail 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')
Put your answers to the following questions in your
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?
Don’t forget to save your answers. (On a Mac, you may need to use the Make Plain Text command in the Format menu before saving the file.)
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 2 icon on the Desktop. This is a slightly different version of Scratch than the one you will use for the homework, but it will work for the purposes of this lab.
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 it 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: Submit your work
You should use Apollo to submit the following files:
- your modified
lab1task2.pyfile containing the lines added in Task 3 and the changes that you made when debugging them
lab1task3.txtfile containing your responses to Task 3
lab1task4-3files containing your programs for Task 4 (Note: You may or may not see a
.sbextension at the end of these filenames.)
Make sure to use these exact file names, or Apollo will not accept your files. If Apollo reports that a file does not have the correct name, you should rename the file using the name listed in the assignment or on the Apollo upload page.
Don’t worry if you didn’t finish all of the tasks. You should just submit whatever work you were able to complete during lab.
Here are the steps:
- Login to Apollo, using the link in the left-hand navigation bar. You will need to use your Kerberos user name and password.
- Check to see that your BU username is at the top of the Apollo page. If it isn’t, click the Log out button and login again.
- Find the appropriate lab section on the main page and click Upload files.
- For each file that you want to submit, find the matching upload section for the file. Make sure that you use the right section for each file. You may upload any number of files at a time.
- Click the Upload button at the bottom of the page.
- Review the upload results. If Apollo reports any issues, return to the upload page by clicking the link at the top of the results page, and try the upload again, per Apollo’s advice.
- Once all of your files have been successfully uploaded, return to the upload page by clicking the link at the top of the results page. The upload page will show you when you uploaded each file, and it will give you a way to view or download the uploaded file. Click on the link for each file so that you can ensure that you submitted the correct file.