1 of 43

Terminal

Jake Shoudy

Oct 21, 2022

CSCI 110 - Lecture 26

2 of 43

Announcements

3 of 43

HW8

Big O Practice and Coding problems using Sets/Dictionaries

Due last night but can turn in up until Sunday night with late days

4 of 43

Project 2: Part 2

More search engine things using 2D Lists :)

Due Sunday October 30th at 11:59pm

5 of 43

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

6 of 43

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:

  • Review quizzes
  • Review homeworks
  • But also projects, labs, slides, replits

7 of 43

8 of 43

Recap

9 of 43

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'

10 of 43

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']

11 of 43

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']

12 of 43

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']

13 of 43

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']

14 of 43

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']

15 of 43

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']

16 of 43

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’]

17 of 43

Terminal

18 of 43

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..

19 of 43

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.

20 of 43

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:

  • Command line
  • Shell

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.

21 of 43

22 of 43

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

23 of 43

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)

24 of 43

Terminal: Practice

Terminal - click here

Then here

25 of 43

Terminal: Practice

Try pwd

26 of 43

Terminal: Practice

Try ls

27 of 43

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)

28 of 43

Terminal: Practice

29 of 43

Terminal: Practice

What directory? Check it!

30 of 43

Terminal: Practice

How to navigate back to folder with main.py?

31 of 43

Terminal: Clear

clear clears terminal and previous commands

32 of 43

Terminal: Practice

Try clear

33 of 43

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

34 of 43

Terminal: Practice

Try mkdir

35 of 43

Terminal: Practice

Try touch

36 of 43

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

37 of 43

Terminal: Practice

Try cat

38 of 43

Terminal: Practice

Try python3

39 of 43

Terminal: Running python with no file

python3 starts the python3 environment

40 of 43

Run Python

In Terminal, try python3

41 of 43

Run Python

Try typing any Python code following >>>

42 of 43

Stop Python

To stop Python: exit()

To know whether Python stopped, the >>> should be replaced by directory

43 of 43

Terminal: Game!