Lab 00 - Getting Started
Due by 11:59pm on January 8, 2025
This lab is all about making sure you have a working development environment, can run the tests, are set up to communicate with the TAs and professors, and get help when needed.
This lab explains how to use your own computer to complete assignments for CS 111 and introduces some of the basics of Python.
This lab is long, there is definitely not enough time to do it all during your scheduled lab session. Please read it all the way through and attempt to set up your development environment (The Python Setup section of this lab) in advance of your scheduled lab time. Then you can work with the TAs in lab if you have an issues with the setup.
If you need any help at any time while working through the lab outside of your lab section, please feel free to come to office hours or post on the course Discord.
Python Setup
If you have Python installed on your computer from CS 110, you don't need a separate or new installation for CS 111. The version you installed for CS 110 is perfectly fine for this class.
The terminal
The terminal is a program that allows you to interact with your computer by entering commands. No matter what operating system you use (Windows, macOS, Linux), the terminal will be an essential tool for CS 111.
macOS/Linux
If you're on a Mac or are using a form of Linux (such as Ubuntu), you
already have a program called Terminal
or something similar on your
computer. Open that up and you should be good to go.
Windows
For the purposes of CS 111, you should use Windows PowerShell as your terminal. PowerShell comes pre-installed on Windows and requires no extra setup. You can simply launch it from the Start menu. Most of the Bash commands covered in this course will work in PowerShell; when an alternate command is needed (such as to unzip a compressed folder), the lab instructions will give both the Bash command and the PowerShell command.
If you have difficulties with copy/paste in PowerShell, you can install Windows Terminal from the Microsoft Store using the instructions below.
Optional: Windows Terminal installation instructions
- From the start menu, open the Microsoft Store
- Search "terminal" in the search bar
- Select the "get" button to install
Install Python 3
Python 3 is the primary programming language used in this course. Use the instructions below to install the Python 3 interpreter. (The instructions may feature older versions of Python 3, but the steps are similar.)
Important: If you already have an older version of Python
installed, please make sure to download and install Python 3.9 or later. You can check your Python version by running the command python ––version
in the terminal.
Linux
Open the terminal and run the Python installation command for your Linux distribution. If your distribution isn't listed below, consult the internet to find the proper command.
Ubuntu 20.04+ or Debian 11+
sudo apt install python3 python-is-python3
Arch Linux
pacman -S python
macOS
Download the macOS 64-bit installer by selecting the downloadable link under Stable Releases at the page below. https://www.python.org/downloads/macos/
You may need to right-click the download icon and select "Open". After installing, please close and open your Terminal.
Windows
Download the Windows installer (64-bit) by selecting the downloadable link under Stable Releases at the page below. https://www.python.org/downloads/windows/
Run the installer and make sure to check the "Add Python 3.x to PATH" box, which will allow you to execute the python
command from your terminal.
After installing, please close and reopen your terminal. Try running the python
command. If this doesn't work, try python3
or py
. Windows may use any of these to refer to Python, so you should use the one that works on your machine.
Other
Download Python for your operating system from the download page.
Install an IDE (Integrated Development Environment)
The Python interpreter that you just installed allows you to run Python code. You will also need a special text editor called an IDE, where you will write Python code.
There are many IDEs out there, each with its own set of features. Visual Studio Code (VS Code) is a popular choice among the staff for this course, as well as PyCharm.
If you are not already familiar with another editor, VS code has often been recommended, though PyCharm is the easiest to install, especially if on a Mac.
Some other editors that are used among staff are listed below as well.
We highly recommend for this class you use either VS Code or PyCharm.
Should I use VS Code or PyCharm?
VS Code pros:
- Many of the TAs for this course are familiar with VS Code and are equipped to help you troubleshoot
- VS Code is highly extensible and can be used to write code in languages other than Python (eg. HTML, JavaScript, etc.)
PyCharm pros:
- Your section TA may be one of the TAs for this course who prefers PyCharm
- PyCharm is optimized for Python, but the same company also has text editors for C, C++, and Java that you will use in future courses.
- The recorded lecture videos demo code in PyCharm.
- Debugging is often easier in PyCharm.
What other text editors are out there?
For your reference, here are some written guides to popular editors used by real developers. Some of these editors are designed to be easy to learn and use, such as VS Code, Atom, and PyCharm. Some of them have complex but powerful commands and functionality, such as Vim and Emacs.
(Although we have included this guide, we do not recommend using editors other than VS Code and PyCharm for this class, since TAs are not equipped to help you troubleshoot other text editors. If you do use other text editors, you may have to troubleshoot any issues on your own.)
- Visual Studio Code: A full-featured desktop editor with many extensions available to support different languages.
- Atom: A more lightweight desktop editor.
- Vim: A command-line editor.
- Emacs: A command-line editor.
- PyCharm: A desktop editor designed for Python.
- Sublime Text: A text editor that works with code.
Warning: Word processors such as Microsoft Word should not be used to edit programs. They are NOT IDEs and word processors can add extra content to documents that will confuse the interpreter. You should NEVER use Microsoft Word or a similar word processor to edit programs for any CS course.
Checkpoint
By this point in the lab, you should have installed a Python interpreter and a text editor. If you had difficulty following any of the steps above, stop here and ask for help before going on.
If your difficulties are caused by your hardware (e.g. you have an iPad or some other device that does not allow you to download software), talk to your TA or a professor about your options so that you do not fall behind in the course while you acquire a suitable device.
If you do not want to invest in a laptop right now (e.g. you are planning on serving a mission and getting a laptop when you return, you are not majoring in CS and you do not need a laptop for your other courses, or you do not have the means to get a laptop this semester), BYU has a laptop rental program for students.
Using the terminal
Let's check if everything was installed properly!
First, open a terminal window. If you're on Windows, launch PowerShell from the Start menu. If you're on macOS or Linux, open the Terminal.
We will be using zsh on Linux, but these commands should work on any of these platforms.
When you first open your terminal, you will start in the "home
directory". The home directory is represented by the ~
symbol,
which you might see at the prompt.
Don't worry if your terminal window doesn't look exactly the same. The important part is that the prompt shows
$
(indicating Bash),%
(indicating zsh), orPS
(PowerShell). If you are on Windows and see something likeC:\Users\Oski>
but noPS
before it, you're in the Command Prompt! Do not use that! Close it and launch PowerShell instead.
Try running echo "$HOME"
. Verify that it displays the path to your
home directory.
Python Interpreter
We can use the terminal to check if your Python 3 interpreter was
installed correctly. Try the following command python
or use python3
.
It might look something like this:
$ python
If the installation worked, you should see some text printed out about
the interpreter followed by >>>
on its own line. It should look something like this:
Python 3.10.9 (main, Dec 19 2022, 17:35:49) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
This is where you can type in Python code.
Try typing some expressions you saw in lecture, or
just play around to see what happens! You can type exit()
or Ctrl-D
to return to your command line.
Important: If the output begins with Python 2.7.18
, you either installed the wrong version of Python, or you need to use the python3
command instead.
Windows troubleshooting
- If the
python
command doesn't run at all: Trypython3
,py
, orpy -3
instead.- If you see
WindowsApps/python: Permission denied
: Open Settings (or right-click the Desktop & click Personalize), search for "App Execution Aliases" (or find it by clicking Home→Apps→App execution aliases), and disable the entries that say "python". (Screenshots here.) Alternatively, go to theWindowsApps
folder whose path is shown and just renamepython.exe
andpython3.exe
to something else, or delete them entirely if you are able to. Then try again.- If Python doesn't run at all: Make sure you set up your "PATH" correctly as shown above.
- If you mixed multiple versions of Python (e.g. 32-bit and 64-bit, or 3.6 and 3.8, etc.): They may conflict. Occasionally, this becomes extremely difficult to fix—even for instructors. Uninstall them one-by-one (the most recent one first), then reinstall only the latest 64-bit version.
- If you manually downloaded Python from its own home page and don't see
64
in the file name: You probably got the 32-bit version. It might work. But if it doesn't, uninstall it before trying another method. If you need to manually find the 64-bit version, look for a recent stablex86-64 executable installer
.Ask for help if you get stuck!
Navigating the Terminal
To test your code in this class we will be running it using the terminal. This will require you open the correct folder on your computer where your code is stored so that when we use the run commands it can find the right files.
Directories
The first command you'll use is ls
. Try typing it in the terminal:
ls
The ls
command lists all the files and folders in the current
directory. A directory is another name for a folder (such as the
Documents
folder). Since you're in the home directory right now, you
should see the contents of your home directory.
This is how you check if you're in the right location.
If
ls
doesn't work, butdir
does: stop! You've mistakenly opened the Windows Command Prompt! Exit it, and run PowerShell instead.
Changing directories
Now that we know what's in a folder when you locate the folder you want to open we need to change directories, using the cd
command.
Let's try moving into your Desktop
directory. First, make sure you're in your home
directory (check for the ~
on your command line). If you are not in
your home directory, type cd ~
to move into the home directory.
Use ls
to see if the Desktop
directory is present. Try typing the
following command into your terminal, which should move you into
that directory:
cd Desktop
On some Windows accounts, your actual Desktop folder might be inside OneDrive:
cd OneDrive/Desktop
If you still can't find your Desktop directory, ask for help.
There are a few ways to return to the home directory:
cd ..
(two dots). The..
means "the parent directory". In this case, the parent directory ofDesktop
is your home directory, so you can usecd ..
to go up one directory.cd ~
(the tilde). Remember that~
means home directory, so this command will always change to your home directory.cd
(cd
on its own). Typing justcd
is a shortcut for typingcd ~
.
You do not have to keep your files on your Desktop if you prefer otherwise. Where you keep your files locally will not affect your grade. Do whatever is easiest and most convenient for you!
Windows PowerShell tip: If you're using PowerShell, you can start it directly by holding Shift, right-clicking inside any folder, and selecting "Open PowerShell Window here". It will automatically
cd
to that folder, so you'll have to runcd ~
to change to your home directory.
More Commands
Now you should know how to check what content is in the current folder you're at and you should know what to change which folder you are in. These two commands should be sufficient for this course.
ls
: lists all files in the current directorycd <path to directory>
: change into the specified directory
Later we will discuss how to run your code once you know your terminal is in the right location. Go ahead and create a CS111 folder for this class with the following sub-folders: labs
, hw
, and projects
on your desktop or other preferred place. If you'd like to learn how to do this and more commands with the terminal visit the Terminal 101 page or refer the Making new Directories section below.
Tip: When you open PyCharm, VS code, or another code-editor there is usually a built-in terminal you can open. Opening a terminal this way will open the terminal in your project/assignment folder by default.
Making New Directories
The next command is called mkdir
, which makes new
directories. Let's make a directory called cs111
on your Desktop
(or some other directory) to store all of the assignments for this class.
First, make sure you are in the Desktop
directory, then type this into
the terminal:
mkdir cs111
A folder named cs111
will appear on your Desktop. You can verify this
by using the ls
command again or by simply checking your Desktop.
At this point, create some more directories. First, we will move to the ~/Desktop/cs111
directory.
cd cs111
Then, let's create folders called proj
, lab
, and hw
inside of the cs111
folder:
cd ~/Desktop/cs111
mkdir proj
mkdir lab
mkdir hw
Now we can list the contents of the directory (using ls
), and we will see
three folders, proj
, lab
, and hw
.
Downloading the Assignment
Download the zip archive,
lab00.zip, which contains all the files that you'll need
for this lab. Once you've done that, let's find the downloaded file. On
most computers, lab00.zip
is probably located in a directory called
Downloads
in your home directory. Use the ls
command to check:
ls ~/Downloads
If you don't see lab00.zip
, ask for help. On some versions of Safari the file may get unzipped for you, in
which case you would just see a new directory named lab00
.
Extracting starter files
You must expand or unzip the zip archive before you can work on the lab files. Different operating systems and different browsers have different ways of unzipping. If the instructions below don't work for you, you can search online or ask a TA.
You can use the terminal to unzip the zip file from the command line. First,
cd
into the directory that contains the zip file:
cd ~/Downloads
If you are not using PowerShell, you can run the
unzip
command with the name of the zip file:unzip lab00.zip
If you are using PowerShell (in Windows), you can run:
Expand-Archive lab00.zip
This will unzip lab00.zip into the downloads folder
OR
Expand-Archive lab00.zip -DestinationPath -Force
Where -DestinationPath will be the directory where the zip file will be unzipped and -Force is optional
You might also be able to extract files without using the terminal by double clicking (or right-clicking) them in your OS's file explorer.
Once you unzip lab00.zip
, you'll have a new folder called lab00
which contains the following files (check it out with cd
and ls
):
lab00.py
: The template file you'll be adding your code totest_lab00.py
: A test file for the assignment that will verify that your code is working properly. The test files provided with each assignment contain the tests that the autograder will run on you code so you can test it in advance to make sure it's working correctly.
Moving Files
If your lab00
folder is still in your Downloads folder,
move the lab00
folder to the lab folder you created earlier:
mv ~/Downloads/lab00 ~/Desktop/cs111/lab
The mv
command will move the ~/Downloads/lab00
folder into
the ~/Desktop/cs111/lab
folder.
Now, go to the lab00
folder that you just moved. Try using cd
to
navigate your own way! If you get stuck, you can use the following
command:
cd ~/Desktop/cs111/lab/lab00
Running tests
In this part of the lab, we just want to verify that you can successfully run the test code that we give you as part of the labs, homework, and projects on your computer. This will make your coding much more efficient than if you have to continually submit to the autograder to check your work.
Don't worry about the details of the output generated by this section of the lab. We'll talk about how to read the output in future lectures and labs. Right now, you are just verifying that it works.
In CS 111, we will use two different methods to check your code. Most labs will have doctests. You can run those by typing:
python3 -m doctest <python file name>
The second method, is to run the test file we provided you. To do this, you'll first have to make sure the byu-pytest-utils
module is installed:
pip3 install byu_pytest_utils
python3 -m pip install byu_pytest_utils
(You may only use pip
or py
. If you get an error, try something similar to this.)
You only have to do that once in the semester. (And if you took CS 110, you probably already have it installed.)
Then, to run the tests for an assignment, go to its folder and run the following command:
python3 -m pytest -vv .
With that background, let's make sure everything is working.
Run the doctests
Go back to the terminal and make sure you are in the lab00
directory we
created earlier (remember, the cd
command lets you change
directories).
In that directory, you can type ls
to verify that you are in the right place, you should see the following file:
lab00.py
: the starter file you just edited
Now, let's test our code to make sure it works. Run this command:
python3 -m doctest lab00.py
Remember, if you are using Windows and the
python3
command doesn't work, try using justpython
orpy
. See the the install Python 3 section for more info and ask for help if you get stuck!
When running the doctests, if you wrote your code correctly, the doctests won't print anything. This is what you want. However, the code we gave you has an error because we want you to see what the error messages look like. If your tests fail, as they should in this case, you'll see a message something like this:
**********************************************************************
File "C:\Users\dagor\PycharmProjects\demo\lab00.py", line 5, in
lab00.eighteen_seventy_five
Failed example:
eighteen_seventy_five()
Expected:
1875
Got:
1874
**********************************************************************
1 items had failures:
1 of 1 in lab00.eighteen_seventy_five
***Test Failed*** 1 failures.
Again, don't worry about the details today, we're just checking to see that things work. If you didn't get an error like the one above, something isn't correct and either the file was edited or there is an issue with your Python installation.
Don't fix the code. We want it to fail in the next section too. We'll fix it after that.
Run the Pytests
Now run the pytests with the command from above to verify that pytest is properly installed and working.
python3 -m pytest -vv .
Again, the code is broken so we expect a failure. It should look something like this:
============================ test session starts =========================
platform win32 -- Python 3.9.13, pytest-7.4.0, pluggy-1.2.0
rootdir: C:\Users\dagor\Documents\Classes\CS111\dev\course-master\Labs\lab00\solution
plugins: byu-pytest-utils-0.7.2
collected 1 item
test_lab00.py F [100%]
=============================== FAILURES =================================
______________________ test_eighteen_seventy_five ________________________
eighteen_seventy_five = <function eighteen_seventy_five at 0x0000014ADF7C59D0>
@with_import("lab00", "eighteen_seventy_five")
def test_eighteen_seventy_five(eighteen_seventy_five):
> assert eighteen_seventy_five() == 1875
E assert 1874 == 1875
E + where 1874 = <function eighteen_seventy_five at 0x0000014ADF7C59D0>()
test_lab00.py:5: AssertionError
======================== short test summary info =========================
FAILED test_lab00.py::test_eighteen_seventy_five - assert 1874 == 1875
=========================== 1 failed in 0.22s ============================
Once again, don't worry about the output right now beyond verifying that it is telling you that something went wrong.
Error free output
Now let's fix the code and see what the tests output when there are no errors.
Start by opening the lab00.py
file in your IDE. The contents should look like this:
def eighteen_seventy_five():
"""Come up with the most creative expression that evaluates to 1875,
using only numbers and the +, *, and - operators.
>>> eighteen_seventy_five()
1875
"""
return 1874
Again, don't worry if you don't understand everything in the file, we haven't covered the details yet (that's coming next week). The error is on the last line where the function is returning the value 1874 when we are expecting it to return 1875. Edit the file to have the correct value. Now let's rerun our tests.
Run the doctests again (python -m doctest lab00.py
). This time there should be no output and you should just get the command prompt back. When running doctests, this is the desired outcome.
Next, try running the pytests again (python3 -m pytest -vv .
). This time, you should see output that looks something like this (assuming your code passed the doctests above):
====================== test session starts =========================
platform linux -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: C:\Users\dagor\Desktop\CS111\labs\lab00
plugins: byu-pytest-utils-0.7.3b0
collected 1 item
test_lab00.py . [100%]
==================== 1 passed in 0.09s =============================
This is what a successful pytest run should look like - a brief summary with no failures being reported.
Now that your development environment is set up, and you can run the tests, let's get your class communication channels set up.
Canvas and Gradescope Setup
To ensure your assignments can be submitted properly and your scores recorded accurately, please review the following instructions:
Canvas Email
Important class announcements will always go out through Canvas so it is important that Canvas is configured properly so that you receive these messages.
In Canvas, make sure that the primary email is your BYU email.
- Go to Canvas.
- On the sidebar, go to Account, then click Settings.
- Check that your BYU email (netid@byu.edu) is shown and is set as the default email (has a star).
- If you do not see your BYU email or if there is no email listed, click + Email Address and enter your BYU email address in the dialog box and click the link that was sent to you.
- If your BYU email address is not the default email, hover over the listing and click the star.
Gradescope Email and Student ID
Gradescope is where you will submit all of your lab, homework, and project assignments for grading. It is important that you are properly connected to Gradescope to recive your grades in the class.
If you have never used Gradescope before, go to the C S 111 Canvas and click the Gradescope link once you have verified your Canvas email. An account will automatically be created for you.
If you have used Gradescope before and C S 111 is not showing up, sign into Gradescope in another tab and click the Gradescope link in the C S 111 Canvas.
To make sure that your accounts match up correctly, please complete the following steps:
- Sign into Gradescope.
- At the bottom of the page, go to Account, Edit Account.
- Make sure your Full Name matches the full name shown in Canvas.
- Make sure that your BYU email is shown under Email Addresses as the Primary Address.
- Make sure that your BYU Student ID (the 9-digit one on your ID card, not your Net ID) is shown under Student ID. If not, enter it without dashes (e.g., if your ID card reads
12-345-6789
, enter123456789
).
- If your BYU email is not showing, click Add Email and enter your BYU email and confirm it.
If you get a banner that says netid@byu.edu is already associated with a Gradescope account, you might have another Gradescope account and must merge your accounts. To do this, sign out of your current account, then sign into the Gradescope account associated with your BYU email. Next, head to the same Edit Account page. Then, click Merge Accounts and enter the email associated with your other Gradescope account.
If you can't log in to Canvas or Gradescope, please talk with your TAs and Professor sooner rather than later to get the issue sorted out. You won't be able to submit assignments until you do. Note: If you just added the class today (or possibly yesterday), it sometimes takes a day or so for BYU's OIT to update the course rosters from the Registrar's Office. This is fairly rare, but they are sometimes overwhelmed the first week of a semester and this may be the reason you can't log in.
Establish Communication with the TAs
Most communication about assignments, due dates, and extra credit will be delivered via the CS 111 Discord Server. To ensure your academic success, join the server by going to https://cs111.byu.edu/discord.
Most section communication will be in your section channel. To be added find the bot-commands
channel and type !rank section##
. Replace the ##
with your assigned lab section number. You will also want to join the channel for your lecture section. Run the same command with your lecture section number.
Explore the Course Website
The CS 111 website is the most important resource to help you succeed in the course. It has all of the assignment specifications and due dates. The homepage has the schedule for the semester/term with links to the lecture slides, lab pages, homework assignments, and projects. For more information about class policies regarding grade breakdown, extensions, late work, etc. visit the Syllabus page.
If you find that you need some extra help during the course visit the staff page to find the TA Help Lab schedule or information on office hours with the professor.
Locate the Open TA Help Lab
This is a demanding class. Many students turn to the internet when the going gets rough. Web searches can be useful, but TA's know the course much better, so visit the Open TA Help Lab instead. Use the map below to locate the open TA help lab.
You may visit the Help Lab at this point, or wait till the end of this Lab.
Appendix: Useful Python command line options
When running a Python file, you can use options on the command line to inspect your code further. Here are a few that will come in handy. If you want to learn more about other Python command-line options, take a look at the documentation.
-
Using no command-line options will run the code in the file you provide and return you to the command line. For example, if we want to run
lab00.py
this way, we would write in the terminal:python3 lab00.py
-
-i
: The-i
option runs your Python script, then opens an interactive session. In an interactive session, you run Python code line by line and get immediate feedback instead of running an entire file all at once. To exit, typeexit()
into the interpreter prompt. You can also use the keyboard shortcutCtrl-D
on Linux/Mac machines orCtrl-Z Enter
on Windows.If you edit the Python file while running it interactively, you will need to exit and restart the interpreter in order for those changes to take effect.
Here's how we can run
lab00.py
interactively:python3 -i lab00.py