0% found this document useful (0 votes)
5 views

Tutorial Week 1 (1)

The tutorial for Week 1 aims to equip students with Python installation, virtual environment setup, and basic programming skills. It covers installing Python, creating and managing virtual environments, using Pip for library management, and writing simple Python programs. Additionally, it includes exercises and a challenge for practical application of the learned concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Tutorial Week 1 (1)

The tutorial for Week 1 aims to equip students with Python installation, virtual environment setup, and basic programming skills. It covers installing Python, creating and managing virtual environments, using Pip for library management, and writing simple Python programs. Additionally, it includes exercises and a challenge for practical application of the learned concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Tutorial Guidelines for Week 1

Expected Outcome

By the end of this tutorial:


 Students will have Python installed and configured.
 They’ll understand the basics of virtual environments and Pip.
 They’ll be able to write and run Python programs.
 They’ll complete exercises and visualize how Python can be used to solve problems

1. Setting Up the Environment

1.1 Installing Python


1. Go to the Python website.
2. Download the latest version for your operating system.
3. During installation:
• Check the box for “Add Python to PATH”.
• Click on Customize Installation and ensure all options are selected.
• Complete the installation process.

1.2 Verifying Installation


1. Open your terminal/command prompt.
2. Run the following command:
python - -version

3. Run the Python interpreter:


Python
You’ll see the Python prompt: >>>.

2. Setting Up a Virtual Environment

2.1 What is a Virtual Environment?

A virtual environment is a self-contained directory that allows you to install Python libraries for
a specific project without affecting the global Python environment.

2.2 Creating a Virtual Environment


1. Open your terminal/command prompt.
2. Navigate to your project folder:
mkdir week1_tutorial
cd week1_tutorial

3. Create a virtual environment:


python -m venv venv

3. Create a virtual environment:


python -m venv venv
4. Activate the virtual environment:
Windows
venv\Scripts\activate
Mac/Linux
source venv/bin/activate

2.3 Verifying the Virtual Environment


1. Once activated, the terminal will show (venv) at the beginning of the prompt.
2. Run:
python –version
The Python version should match your installed version.

2.4 Deactivating the Virtual Environment

When done, deactivate it by running:


Deactivate

3. Installing and Using Pip

3.1 What is Pip?

Pip is a package manager for Python that allows you to install and manage additional libraries.

3.2 Checking Pip Installation


1. Run the following command to check if Pip is installed:
pip –version
Example Output: pip 21.x.x

3.3 Installing Libraries with Pip


1. Install a library (e.g., requests):
pip install requests
2. Verify the installation:
pip show requests

3.4 Uninstalling a Library


To uninstall a library:
pip uninstall requests

4. Writing Your First Python Program


Example: “Hello, World!”
1. Create a new file named hello_world.py:
print("Hello, World!")
2. Run the file:
• Save the file in your project folder.
• Run:
python hello_world.py
5. Variables and Data Types
Example 1: Working with Strings
name = "Alice"
print("Hello, " + name + "!")

Example 2: Simple Arithmetic


a = 10
b=5
sum = a + b
print("The sum is:", sum)

Example 3: User Input


name = input("What is your name? ")
print("Welcome, " + name + "!")

Exercise 1: Greeting the User


name = input("Enter your name: ")
print("Hello, " + name + "! Welcome to Python programming.")

Exercise 2: Add Two Numbers


num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
result = num1 + num2
print("The sum is:", result)

Exercise 3: Simple Interest Calculator


principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the rate of interest: "))
time = float(input("Enter the time (in years): "))
simple_interest = (principal * rate * time) / 100
print("The Simple Interest is:", simple_interest)

7. Challenge

Task: Temperature Conversion

Write a program to convert Celsius to Fahrenheit.


celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9/5) + 32
print("Temperature in Fahrenheit:", fahrenheit)

You might also like