0% found this document useful (0 votes)
2 views9 pages

Terminal Gedit Python

This document provides an overview of basic shell commands and their functions, such as listing files, creating directories, and changing directories. It also explains how to open and use gedit and Python from the terminal, including setting preferences in gedit for coding. Additionally, it touches on defining functions and assigning variables in Python, with references for further learning.

Uploaded by

pedrojambo727
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views9 pages

Terminal Gedit Python

This document provides an overview of basic shell commands and their functions, such as listing files, creating directories, and changing directories. It also explains how to open and use gedit and Python from the terminal, including setting preferences in gedit for coding. Additionally, it touches on defining functions and assigning variables in Python, with references for further learning.

Uploaded by

pedrojambo727
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

LAB 2

Terminal / Gedit

Python

Ronnie Ghose
S HELL C OMMANDS

Command ‘Acronym’ What does it do?

Lists the files and directories/folders


ls List
in your current folder

mkdir
Make directory Make a folder in your current directory
<directory name>

Print working
pwd Print where you are!
directory
Change directories – Like clicking a
cd Change Directory folder Finder (mac) or Explorer
(windows)
SO WHAT ’ S A SHELL ?

This is called the prompt, it’s the place


you type things in the shell (if you see the
box on the right of the $.

You get to the shell by clicking Terminal –


yours may be in System Tools instead of
Accessories

Shells are programs for running other programs. We’re


going to use them to run gedit and python3 in this
class, but you can run any program you have installed
on your computer through it!
LS

Using ls is just like using the file browser

PWD

If you see the path (the location of where


you are) that pwd prints out, it’s the same
as using the file explorer on the left

MKDIR

We make a new folder called lab4, using ls to see what


folders are there before, and then use ls to confirm it
exists after we made it
CD

We first see where we are using pwd and then


enter the lab4 folder using the cd command,
verifying we are there using pwd again! (cd like
double clicking a folder to enter it in a file explorer
such as Windows Explorer or Finder)

You can cd <folder name> to go into a directory/folder and cd .. if you want to exit a
folder.
Opening Programs In Shell
We are going to make a file called [Link] in the lab4 folder
using gedit after opening it from the shell

3 2

1. Open gedit in terminal with the & (it means you want to use
the terminal even after you launched the program, otherwise
the terminal will only run gedit and will not be available for
further commands – like if you want to run python in the same
terminal)
2. Enter your code!
3. Save it in the lab4 folder as [Link] (you don’t need to
change “character encoding” or “line encoding”)
4. Verify it’s in the folder using the file browser and the ls
command
Python
Fun fact: Python is named after Monty Python

Setting up Gedit
1

1,2. Check Edit -> Preferences -> Display line numbers if you
want the line numbers next to each line of code
Also Highlight matching brackets is very useful when
looking for that missing bracket!
3. Make sure at the bottom you are using spaces and there
are 4 spaces for each tab (that way you can hit tab instead of
space 4 times for every python block – such as in functions).
How do I know I’m in Python vs Shell?

Python has the >>> prompt, Shell has the bash-4.1 or your
<Andrew id>@<the computer name>. You can exit Python using
Ctrl-D or the quit() function

Assigning variables and some tricky operators in Python

( refer to lecture notes [Link]


for more comprehensive notes )
Functions in Python

Things to note:
Def means define, you’re defining a function, telling it what to
expect, and then ending with a semicolon.
This is just like in math where you say f(x) = 2*x, you would
say
def f(x):
return 2*x

Return means return a value! So if you do for example


add_two(add_three(2)), you want add_three to return a value, not
Just print out something. Refer to lecture notes here for more details and
examples! Also if you ever want practice problems / have questions / want
clarification about lab, remember we have office hours! 

You might also like