CS 1

Short Assignment: Printing to the screen

This short assignment is a bit wordier than will be typical. It also has a lot of technical detail about installing the PyCharm software and using it. It is to get you started off. Future assignments will be more creative and will require less following of picky instructions.

Things to do to get started

  1. Familiarize yourself with the layout of the CS 1 website. Most of the course materials will reside on the website.

  2. If PyCharm is not already running, launch it.

  3. Just as you did when creating the cs1proj when you installed PyCharm, select Create New Project. You may enter whatever project name you like. I used SA1 by changing untitled to SA1. Make sure that you have the Python interpreter that you selected when you set up PyCharm.

    I’m using a Mac. If you’re using Windows, it will be similar. Make sure to choose the Python interpreter that you set up when you installed PyCharm.

  4. Remember how you were supposed to keep the file cs1lib.py that you downloaded nice and accessible? Find it, and copy it onto the name of your project in the Project tab.

    If you see a window that says These files do not belong to the project, just click OK.

  5. The code that you’ll first run is mystery.py. Download mystery.py onto your hard drive. To download the file right click and select “Download link as” or “Save link as” in the menu. Don’t save this file into the workspace folder that you made, however. Just save it someplace innocuous, such as your Desktop, or leave it in your Downloads folder.

    Copy the mystery.py file from wherever you saved it onto the name of your project in the Project tab, clicking OK to complete the copying.

  6. Run mystery.py. Recall that you can either single-click on mystery.py in the Project tab, select Run … from the Run menu, and then mystery, or you can right-click on mystery.py in the Project tab and then choose Run ‘mystery’ from the popup menu. If you’re on a Mac, don’t worry about the red text you get in the console pane.

  7. A window with some graphics should appear. Write down what you see. You may click on the window’s close button whenever you like.

  8. Next, remove mystery.py from the project. To do so, select it again by clicking on mystery.py in the Project tab, go to the Edit menu, and select Delete. When you are asked, Delete file “mystery.py” from the project?, click OK.

  9. Now you will type in a new program that you will write. This program prints your name with a simple text-based logo. First, click on SA1 (or your project name) in the Project tab. Then go to the File menu, choose New…, and then choose Python File. Type in the name of the file containing your Python program. Make sure that the name ends with .py. Then click OK. For example, I named my file logo.py.

    The main part of the window will be a tab labeled with the name of your program (logo.py in our example).

  10. Type in the logo program, with a logo of your choosing. (See the explanation below under Exercises.) You can model it after the class examples. PyCharm automatically indents your program as you type it (though you won’t need to indent any lines for this program), and it does things like putting closing parentheses when you type the opening ones. Also, if a line has a syntax error, a red squiggle will appear at the point of the error.

  11. Run your program. By now you know how. Either your program will run correctly (writing to the console pane) or you will see an error message.

    Your program might not run correctly the first time. If that’s the case, then you have had an early initiation into the world of programming. Errors are common in programming. We all make them. Even me. Fixing mistakes is a significant part of developing programs. If you have an error, check the syntax of your program carefully. Are the tabs, parentheses, colons, and quotation marks correctly placed? Did you misspell something?

  12. When your program execution completes, you’ll be left with console pane containing the output of your program. We want to see the output of your program. Take a screenshot.

Exercises:

(These are the “official” things to do and turn in.)

  1. Run the Python program mystery.py, and write a short text file describing what you observe, using Notepad (Windows) or TextEdit (Mac). Save your text file as observation.txt.

  2. Write a Python program that prints out a logo containing your name. Hany Farid, who taught this course in a previous term, chose the following:

      *     ******
      *     *
      *     *
      **********
      *     *
      *     *
      *     * Hany Farid

Please feel free to create your own design. (As I often say, “I don’t know what I like, but I know art.”) The program should be very simple, essentially consisting of just a few print statements. In this example, the third statement might be

print " *      *"
  1. Take a screenshot of the PyCharm window (or the entire screen) showing the console window after running your logo.py. Save the result as either logo_output.tiff (Mac) or logo_output.bmp (Windows).

What to turn in

There are three things you need to turn in:

  1. observation.txt (your description of the result of running mystery.py.)

  2. screenshot of the output you get when you run mystery.py (a file in any standard image format.)

  3. logo.py (or whatever you called the program you wrote to display your logo.)

  4. logo_output.tiff or logo_output.png (or any other standard image format.)

Please remember in all assignments that editing the output of the program before printing it is a violation of the Academic Honor Principle. Make sure that the output you turn in comes from the very same program that you turn in. If you make any change to the code, no matter how insignificant you think they might be, rerun your program to produce new output!

How to turn in your assignment

Submit the files through Canvas.

You are done. Whew! Future short assignments will have far fewer picky details. This one was really detailed because it’s your first time using PyCharm and your first time running and writing a Python program.

Honor Code

The consequences of violating the Honor Code can be severe. Please always keep in mind the word and spirit of the Honor Code.

An important reminder

Keep up to date. Do your studying for each class—not just once a week. Do lots of simple exercises on your computer. Even when you think you understand how to do something, you will discover that it is still important to actually do it with your own fingers, on your own computer. Programming is not a spectator sport.