- Get acquainted with the PyCharm development environment
- To re-acquaint yourself with programming in Python
- To practice modularity and information hiding
- If you haven't already logged into a lab machine, do so now. I can
help you with username/password information.
- Make a "csc120" folder. In that
folder, make a "workspace" folder. You can use this
folder for both labs and projects. Each lab or project will be a
folder within the workshop folder.
Integrated Development Environments
In previous classes where you've used Python, you used a program called
Idle to edit and run your programs. However, Python does not
equal Idle. Python is a language in which you can
write programs, but the tool you use to edit those programs is
simply a text editor. Any text editor will do. [Note: Similarly,
English is not Microsoft Word].
Once your programs are in the right language (in this case Python), they
can be compiled or interpreted by appropriate tools (in
this case, the Python interpreter). When you used Idle before, it
provided a window for text file editing (where you could type your
programs) and a way to run those programs. To run the programs, Idle would
call the Python interpreter to do the job. Because editing and running
are integrated together in Idle, we call Idle an Integrated
Development Environment (IDE).
Another IDE, one used by professional developers, is
called PyCharm. PyCharm is made by the JetBrains company,
which also makes other IDEs, including ones designed for Java, C++,
Ruby, etc.... In this course, you will use PyCharm instead of Idle.
But remember, the language you are using is still the same old
Python you are familiar with.
Getting Started with PyCharm
Launch PyCharm from the dock icon, if one is available, or you can
find it by using the launcher. You'll be presented with options
to Create New Project or Open an existing one. Choose the Create New Project option, which will result in a window like the following:
You can click the button with the 3 dots to the right of the
Location field to navigate to the csc120/workspace folder you created
earlier. In the example above, I'm creating a project called CassLab1
in my workspace folder. Please name your project with your
name and lab number as well.
Add some Starter Code
In many labs, including this one, I'll be providing you with
starter code that you need to augment with your own code. Download
and add main.py to your
- Right-click the link above and choose Save as...,
and save the file to your project folder. Then in the lefthand pane in
PyCharm, you should see that main.py is in the project.
This program lets the user play a very simple game of dominoes. You can
imagine that this might be a very early step along the way to making a
full-featured dominoes game.
Have a look around
Now that you have a project and some code, explore to see what you have:
- Read the code. Can you figure out what each line is trying to do?
- Can you tell what functions are expected from the boneyard
and domino module?
- Look at your files and folders. Notice that your project is just a
folder (named the same as your project) that contains the .py files
you've added to it.
Add the required modules
Now that you have an idea of what functions the domino
and boneyard modules must provide, you'll be adding those modules
to your project:
- Add the provided boneyard.py to your
project. Download it into the project folder and you should see it show
up in PyCharm.
- Read the boneyard module. Notice that it provides the
functions used in the main module. If there are functions you don't
understand, you can look them up in
Notice that the module represents the boneyard as a
list of domino representations, which are created using the create
function in the domino module.
- Add a new domino.py module to your project. It needs to have
all of the functions that the main and boneyard modules expect it to have
(i.e. create(left, right), get_left(domino), get_right(domino),
and as_str(domino)). Start by having the two getters
just return 0 and having the other two functions just pass.
- Now, you can run the code. The first time you run the code, you need to tell
PyCharm what you want to run: choose "Run..." from the "Run" menu,
and select main.py. Afterwards, you can re-run by
clicking the green play button in the toolbar. Note: the program
won't work, but it should run. To stop it running, you can click the red
X on the left hand side of the output console.
Finish the domino module
- Start by writing as_str:
return "[%d | %d]" % (get_left(domino), get_right(domino))
- Re-run the program and see what's changed.
- Write the create function, which needs to create a
representation for a domino with the given left and right values. For
this lab, you should use a tuple to represent a domino (where the left
value is the first item in the tuple and the right value is the second
value). Recall that (x, y) creates a tuple with values x and y.
- Re-run the program and see what's changed.
- Now, write get_left and get_right. These functions
get the left value and the right value of a given domino. The
representation created by the create function determines how
these two functions must do their job.
- Re-run the program and see what's changed. Does the program do what we
How to turn in this lab
Before turning in any program in this class, remember this mantra:
Just because it works doesn't mean it's good.
Part of your grade will also come from things like how understandable
and readable your code is. You will also be graded on the neatness,
presentation, and style of your program code.
For all labs, turn in only an electronic version. Please create a
tarball of your PyCharm project and email it to me at email@example.com.
Follow these instructions (or ask me to show you a shortcut):
- In a terminal window, go to your workspace folder (the folder that
contains the folders that are your PyCharm projects).
- Create the tarball with something like this:
tar -cvzf CassLab1.tar.gz CassLab1
page for an explanation of what that command is doing.
- Email the created file (the tar.gz tarball) to me.
Ask for help if you're having problems!