---
# System prepended metadata

title: Lab 01
tags: [' Spring-2020', Labs]

---

---
layout: page
tags: Labs, Spring-2020
title: Lab 01
permalink: /spring2020/labs/lab1
---
# Lab 1: Terminal and Department Tools

## Section 1: You and Your Department Machine
Howdy Y'all! Welcome to your first lab in CS0112! This is going to be a great semester of learning and expanding on your CS skills, all while reminiscing on this past decade. In order to make sure we remember all of the good times in today's lab and throughout the semester, today we are going to learn how to interact and use the department machines found throughout the CIT!

Interacting with the department machines and UNIX/LINUX is something that becomes more common as you begin to take higher level CS classes. Many classes, including ours, have scripts and directories that handle turning in files, coping source code to your personal directory, as well as providing demos for projects. Learning how to navigate the department system in order to find and interact with the provided resources is a useful skill to build early into the semester!

### Background
Macklemore has been trying to convince you that he was born in 2014 for the past week. Even though you are 90% sure that he was not born in 2014 because he is 36 years old. Macklemore, however, does not believe your math. He only trusts computers!! He claims he ran a script on a department machine in the CIT that told him he was born in the 2010's. Knowing that the script must be broken somewhere, you decide to fix the script to prove to Macklemore that 36 years ago was before 2010!

### Instructions
When you first interact with a department machine, you should see a login prompt asking you for your username and password. Within the CS department, your username and password are as follows:
> Username: **Brown Username**
> Password: **Brown Password**

**Be sure to clear the text blocks before trying to enter your username or password! Sometimes there is whitespace left in the blocks that will cause your login to fail!**

Once you login, you should land on a desktop screen that looks something like this:

![Home Screen](https://i.imgur.com/0kmvFDD.png)


If your desktop screen looks drastically different from this setup, please call over a TA!

In order to interact and run scripts that are found in the department file system, we will have to use the terminal! Terminal is a lower level, text input based version of a file system such as finder on Mac or file explorer on windows. Much like those applications, with a terminal you can navigate a file system using built-in commands provided by the terminal. A few commands that are important for navigating the system are:

> ```ls```: lists contents of the current directory you are in.
> ```cd```: change directory, used to navigate from one directory to another.
> ```pwd```: present working directory, prints the current directory you are in.
> ```touch```: creates a file in the current directory you are in.


In order to open the terminal on the department machine, click the black box on the bottom tool bar of your home screen.

![](https://i.imgur.com/KYuj6wt.png)


Now that you have the terminal open, the window should look like this:

![](https://i.imgur.com/jxtpt31.png)


- To start interacting with the terminal, use the ```ls``` command to check the contents of the current directory you're in. You should see names such as Public, Desktop, and Documents in the list of directories in /gpf/main/home/[your-login]. 
- For this lab, we will need to install the lab files into your course directory. In order to do this, run the command ```cs0112_install lab01```. This will setup your course directory for the course, as well as putting the files for this lab into your course directory.
- using the ls command along with the cd command, navigate through the new course folder and find the python file called ```age_checker.py```! 
> **TIP: in order to travel into a folder that is in the current directory you are in, use the command cd as follows: ```cd [directory you want to go in]``` example: ``cd course``**
> **TIP: To go back up a directory in the file system, use the command ``cd ..``**

___
### CHECKPOINT:
**Call over a TA after you have found the lab01 folder through your terminal.**
___


## Section 2: Move Like A Snake (Python)
 

## Problem 1
Now that you've finally found Macklemore's python file, you can debug his code and prove that 36 years ago was before 2010. 

### Instructions
To view Macklemore's code, you will use a text editor. Text editors are programs that allow you to view and modify code. The decision to use one text editor versus another is up to personal preference. Some common ones are Atom, Sublime, and PyCharm. 
- Run ```atom <filename.py>``` or ```pycharm <filename.py>``` or ```subl <filename.py>``` in the terminal to examine the python file. 


Do you notice anything wrong? 

- Check the ouput of the code by running the following command in your terminal: ```python3 <filename.py>```. Side-note: To successfully run a python script, you must be in the same directory as the file. For example, if you have a python file saved on the Desktop, you would not be able to run it from the cs112 directory or the Documents folder

If you would like to run Python code outside of a text editor, you can use a REPL, Read-Eval-Print Loop. The Python REPL is basically a terminal within the terminal that interprets Python commands rather than UNIX commands. The REPL can be helpful when writing code and debugging because you can see the output of a particular command. To use the REPL, type ```python3``` in the terminal. Try running these simple commands:

     >>> 2+2
     >>> l = [1,2,3]
     >>> l
     >>> x = 5
     >>> y = 4
     >>> x+y
- Use the REPL to ensure that the current_year variable has the correct value, 2020. Hint: ```import datetime``` before running anything else. 
___

### CHECKPOINT:
**Call over a TA once you've verified the current year in the REPL.**
___

- Finally, find and correct the error in the code. Check your solution by uncommenting the test function ```test_born_in_2010s``` and running the script again. 
___

### CHECKPOINT:
**Call over a TA once you successfully passed all the tests.**
___

## Success!

Macklemore now owes you a private concert!

