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.
Familiarize yourself with the layout of the CS 1 website. Most of the course materials will reside on the website.
If PyCharm is not already running, launch it.
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.
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.
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.
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.
A window with some graphics should appear. Write down what you see. You may click on the window’s close button whenever you like.
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.
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).
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.
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?
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 (see below how to do this). You will need to upload this logo screenshot to Canvas (see section on What to turn in).
macOS screenshot instructions: You can take a shot of just the window you want by using the Screenshot utility (called “Grab” on older versions of macOS). You can also use the keyboard shortcut: ⌘ + Shift + 4 and then either drag the cursor to take a screenshot of a portion of your screen, or hit the space bar and then click to take a screenshot of a single window. The screenshot is typically saved to the Desktop. Save the screenshot as logo_output.png (or any other image file type .tiff, or .jpg or .jpeg).
Windows screenshot instructions: Press the PrntScrn button on your keyboard, open the Microsoft Paint utility, and save the screenshot as logo_output.bmp.
(These are the “official” things to do and turn in.)
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.
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 " * *"
There are three things you need to turn in:
observation.txt (your description of the result of running mystery.py.)
screenshot of the output you get when you run mystery.py (a file in any standard image format.)
logo.py (or whatever you called the program you wrote to display your logo.)
screenshot of the output you get when you run logo.py (a file in any 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!
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.
The consequences of violating the Honor Code can be severe. Please always keep in mind the word and spirit of the Honor Code.
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.