Module 1

Introduction to Python & VS Code

Learn Python fundamentals and set up your development environment

Learning Objectives

Understand Python fundamentals and syntax

Set up VS Code for Python development

Write and execute your first Python programs

Master variables, data types, and operators

Control program flow with if/else and loops

Write reusable functions and understand scope

Setting Up VS Code

Installation & Configuration
Get your development environment ready

Step 1: Install VS Code

Download VS Code from code.visualstudio.com and install it for your operating system.

Step 2: Install Essential Extensions

Python - Official Python extension by Microsoft

Pylance - Fast, feature-rich language support

GitHub Copilot - AI pair programmer

Pylint - Code quality checker

Black Formatter - Automatic code formatting

Step 3: Configure Python Interpreter

Press Ctrl+Shift+P and search for Python: Select Interpreter to choose your Python installation.

Python Fundamentals

Variables and Assignment
Store and manipulate data in your programs

Variables are containers for storing data values. In Python, you create a variable by assigning a value to a name.

python
name = "Alice"
age = 25
height = 5.7
is_student = True

print(f"Name: {name}")
print(f"Age: {age}")
print(type(name))  # str
print(type(age))   # int

Control Flow

Conditional Statements
python
score = 85

if score >= 90:
    grade = "A"
elif score >= 80:
    grade = "B"
elif score >= 70:
    grade = "C"
else:
    grade = "F"

print(f"Grade: {grade}")

Functions

Writing Reusable Code
Functions help organize and reuse code
python
def greet(name):
    print(f"Hello, {name}!")

greet("Alice")

def add(a, b):
    return a + b

result = add(5, 3)
print(result)  # 8

def introduce(name, age=25):
    print(f"My name is {name} and I am {age}")

introduce("Bob")
introduce("Charlie", 30)

Hands-On Exercise

Build a Simple CLI Calculator
Practice what you have learned

Create a program that prompts for two numbers and an operation, performs the calculation, and asks to continue.

python
def calculator():
    while True:
        try:
            num1 = float(input("Enter first number: "))
            num2 = float(input("Enter second number: "))
            operation = input("Enter operation (+, -, *, /): ")
            
            if operation == "+":
                result = num1 + num2
            elif operation == "-":
                result = num1 - num2
            elif operation == "*":
                result = num1 * num2
            elif operation == "/":
                if num2 == 0:
                    print("Cannot divide by zero")
                    continue
                result = num1 / num2
            else:
                print("Invalid operation")
                continue
            
            print(f"Result: {result}")
            
            again = input("Calculate again? (yes/no): ")
            if again.lower() != "yes":
                break
        except ValueError:
            print("Invalid input")

if __name__ == "__main__":
    calculator()