CS 111
Spring 2019

Lab 1: Getting started

Task 0: Review lab policies

Note

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:

  1. 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.)

  2. 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.edu and click Connect.

  3. Enter your BU email address in the form username@bu.edu and your Kerberos password, and click Login.

  4. 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.

Notes

  • 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:

Task 2: Explore IDLE

First, start the IDLE program:

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.

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:

IDLE

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.

  1. 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')
    
  2. Consider the following two lines of the program:

    weeks = days // 7
    print('that is approximately', weeks, 'weeks')
    
    1. What is the difference between weeks and 'weeks'?

    2. Why does the program print 5 weeks instead of 6 or 5.7142857...?

    3. How could we make the program print a more precise result for the number of weeks?

  3. Copy and paste the following lines of buggy code into your lab1task2.py file 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.py file and not to the Python Shell.

  4. Save the changes to the program using Ctrl-S. Then try to run it using F5. What happens?

  5. 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:

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.

  1. 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-1 using the File->Save menu option.

  2. 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 random operator 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-2 using the File->Save menu option.

  3. Use the File->Save As menu option to save a copy of your program for the previous exercise, saving it as lab1task4-3.

    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 all or stop script command, 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 stop command 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 all or 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:

  1. Login to Gradescope by clicking the following link:

    Gradescope

    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.

  2. 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.)

  3. 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.)

  4. Add your two files (lab1task2.py and 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.

  5. Click the Upload button.

  6. You should see a box saying that your submission was successful. Click the (x) button to close that box.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

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.