Before we begin with the lab assignment, make sure you have the following setups done with the help of your TAs:
Open the Terminal
Basic Commands
pwd
: Print Working Directory
pwd
Outputs the current directory you are in.
ls
: List Directory Contents
ls
Lists files and directories in the current directory.
cd
: Change Directory
cd /path/to/directory
Changes the current directory to the specified path.
mkdir
: Make Directory
mkdir my_directory
Creates a new directory named my_directory
.
touch
: Create a New File
touch myfile.txt
Creates a new empty file named myfile.txt
.
rm
: Remove File
rm myfile.txt
Deletes the file named myfile.txt
.
rmdir
: Remove Directory
rmdir my_directory
Deletes the directory named my_directory
(must be empty).
cp
: Copy Files or Directories
cp source_file destination_file
Copies source_file
to destination_file
.
mv
: Move or Rename Files or Directories
mv old_name new_name
Renames old_name
to new_name
or moves old_name
to new_name
if it is a path.
Exercise:
<YourEntryNumber>_COL100
(Eg 2024CS10001_COL100
).<YourEntryNumber>_COL100
, create a file named hello.txt
.cs_intro
to verify the file exists.hello.txt
to welcome.txt
.welcome.txt
.Check if Python is Installed
python3 --version
If Python is installed, it will display the version number.
Installing Python3
python3 --version
to check./bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install python3
sudo apt update
sudo apt install python3
sudo dnf install python3
Verify the Installation
python3 --version
You should see the version number of Python3.
Create a New Python File
cs_intro
directory:cd cs_intro
hello.py
:touch hello.py
Write Your First Python Program
hello.py
in a text editor (nano, vim, VS Code, etc.):nano hello.py
hello.py
:print("Hello, world!")
CTRL + X
, then Y
, then Enter
).Run Your Python Program
python3 hello.py
You should see the output:
Hello, world!