Terminal
Jake Shoudy
Oct 21, 2022
CSCI 110 - Lecture 26
Announcements
HW8
Big O Practice and Coding problems using Sets/Dictionaries
Due last night but can turn in up until Sunday night with late days
Project 2: Part 2
More search engine things using 2D Lists :)
Due Sunday October 30th at 11:59pm
Project 1: Part 5 (Optional)
Multiplayer blackjack and score keeping.
Earn up to 50 points back on project 1 or 12.5 points on midterm 1.
Show Jake your code in person for grading
Due Monday October 31st
Exam 2: Wednesday Oct 26
Topics (up until end of last week):
Binary <-> Base 10
Data types
Operators (arithmetic, comparison, logical)
Variables
if / elif / else
while loops
Strings (length, index, slice)
Functions
Will include short answer & coding questions
For Loops
Lists
2D Lists
Big O
Sets
Dictionaries
How to prepare:
Recap
Nested Dictionaries
songs = {
'Circles': {'artist': 'Post Malone', 'genre': 'Pop'},
'Ransom': {'artist': 'Lil Teccae', 'genre': 'Hip Hop/Rap'},
'BOP': {'artist': 'DaBaby', 'genre': 'Hip Hop/Rap'},
'Truth Hurts': {'artist': 'Lizzo', 'genre': 'Pop'},
'223\'s': {'artist': 'YNW Melly', 'genre': 'Hip Hop/Rap'},
}
print(songs['Circles']['artist'])
'Post Malone'
Nested Dictionaries and Lists
songs = {
'Post Malone': [
{'title': 'Circles', 'year': 2019},
{'title': 'Goodbyes', 'year': 2019},
],
'Lizzo': [
{'title': 'Truth Hurts', 'year': 2019},
{'title': 'Good As Hell', 'year': 2016},
],
}
songs['Lizzo'][1]['year']
Nested Dictionaries and Lists
songs = {
'Post Malone': [
{'title': 'Circles', 'year': 2019},
{'title': 'Goodbyes', 'year': 2019},
],
'Lizzo': [
{'title': 'Truth Hurts', 'year': 2019},
{'title': 'Good As Hell', 'year': 2016},
],
}
songs['Lizzo'][1]['year']
Nested Dictionaries and Lists
songs = {
'Post Malone': [
{'title': 'Circles', 'year': 2019},
{'title': 'Goodbyes', 'year': 2019},
],
'Lizzo': [
{'title': 'Truth Hurts', 'year': 2019},
{'title': 'Good As Hell', 'year': 2016},
],
}
songs['Lizzo'][1]['year']
Nested Dictionaries and Lists
songs = {
'Post Malone': [
{'title': 'Circles', 'year': 2019},
{'title': 'Goodbyes', 'year': 2019},
],
'Lizzo': [
{'title': 'Truth Hurts', 'year': 2019},
{'title': 'Good As Hell', 'year': 2016},
],
}
songs['Lizzo'][1]['year']
Nested Dictionaries and Lists
songs = {
'Post Malone': [
{'title': 'Circles', 'year': 2019},
{'title': 'Goodbyes', 'year': 2019},
],
'Lizzo': [
{'title': 'Truth Hurts', 'year': 2019},
{'title': 'Good As Hell', 'year': 2016},
],
}
songs['Lizzo'][1]['year']
Nested Dictionaries and Lists
songs = {
'Post Malone': [
{'title': 'Circles', 'year': 2019},
{'title': 'Goodbyes', 'year': 2019},
],
'Lizzo': [
{'title': 'Truth Hurts', 'year': 2019},
{'title': 'Good As Hell', 'year': 2016},
],
}
songs['Lizzo'][1]['year']
Nested Nested Nested Dictionaries
population = {
'North America': {
'United States': {
...
'Washington': {...}
'Tennessee': {
'Nashville': 692587,
'Memphis': 650910,
'Chatanooga': 181370,
...
},
},
'Mexico': {...},
...
},
'Africa': {...},
...
}
population[‘North America’][‘United States’]
[‘Tennessee’][‘Nashville’]
Terminal
Operating Systems
The operating system of a computer is the software that manages all of the hardware and programs running on a computer.
MacOS on Mac computers, Windows 11 on Microsoft, ChromeOS on Chromebooks, and Linux on most other devices..
Linux
You have to pay for MacOS, Windows, or ChromeOS - Linux is open-source, so it is free to use. For this reason, most computer servers in datacenters run Linux
Usually you connect to a datacenter computer over the internet, so there’s no screen - most interactions with Linux are via the terminal.
Terminal
The terminal is a text-based interface used to control a computer.
As a software engineer, you will need to know to use terminal. Other terms you might here that are somewhat interchangeable:
MacOS’s terminal is based on Unix terminal, so is almost identical to Linux terminals. If you have a Windows machine, make sure you get practice using Linux terminals in a cloud IDE like Replit or vscode.dev.
Terminal
Navigate different folders (called directories)
-> need to be in correct folder in order to run file with code
List folders and files in current folder
Create files and directories
Run code
Terminal: Current Folder
pwd current folder
ls lists folders and files in current folder
ls -l lists folders and files in current folder (long format)
Terminal: Practice
Terminal - click here
Then here
Terminal: Practice
Try pwd
Terminal: Practice
Try ls
Terminal: Change Folders
cd [folder] change folders (aka directory)
example: cd ~/home/jshoudy/cs110/practice
Special cd commands:
cd go to root directory (same as cd ~)
cd .. go to parent directory (directory containing this directory)
cd . go to current directory (no change)
Terminal: Practice
Terminal: Practice
What directory? Check it!
Terminal: Practice
How to navigate back to folder with main.py?
Terminal: Clear
clear clears terminal and previous commands
Terminal: Practice
Try clear
Terminal: Make Directories and Files
mkdir [directory_name] creates a new directory
rmdir [directory_name] removes a directory
touch [file_name] creates a new file
rm [file_name] removes a file
Terminal: Practice
Try mkdir
Terminal: Practice
Try touch
Terminal: Running code in a file
vim [file_name] open vim to edit a file (many options and
strong opinions here)
cat [file_name] see contents of a file
python3 [file_name] runs the file as python code
Terminal: Practice
Try cat
Terminal: Practice
Try python3
Terminal: Running python with no file
python3 starts the python3 environment
Run Python
In Terminal, try python3
Run Python
Try typing any Python code following >>>
Stop Python
To stop Python: exit()
To know whether Python stopped, the >>> should be replaced by directory
Terminal: Game!