Crash Course – Python

Objective:

By the end of this one-hour crash course, participants will have a basic understanding of Python syntax, variables, data types, control flow, functions, and simple file handling.

Course Outline:

Introduction to Python (5 minutes)

  • Brief history of Python
  • Python’s popularity and applications
  • Setting up Python environment

Basic Syntax and Variables (10 minutes)

# This is a comment
greeting = "Hello, World!"
print(greeting)

Data Types and Operations (10 minutes)

# Integers and Floats
x = 5
y = 2.5
print(x + y)  # Addition

# Strings
name = "Alice"
print(name.upper())  # Convert to uppercase

Control Flow (10 minutes)

# Conditional statement
num = 10
if num > 5:
    print("Number is greater than 5")
else:
    print("Number is 5 or less")

# Loop
for i in range(5):
    print(i)

Functions (10 minutes)

def greet(name):
    return f"Hello, {name}!"

print(greet("Bob"))

Lists and Dictionaries (10 minutes)

# List
fruits = ["apple", "banana", "cherry"]
fruits.append("date")
print(fruits)

# Dictionary
person = {"name": "Alice", "age": 25}
print(person["name"])

File Handling (5 minutes)

# Writing to a file
with open("example.txt", "w") as file:
    file.write("Hello, World!")

# Reading from a file
with open("example.txt", "r") as file:
    content = file.read()
    print(content)