CodingNic

Modules, Packages, and Virtual Environments

Practical Projects

Modules, Packages, and Virtual Environments 36 min read

Practical Projects

Practical Projects

Great job learning modules, packages, pip, virtual environments, and requirements files.

Now it is time to practice by building real projects with clear instructions.


Project 1: Calculator Module App

Build a small calculator using your own module.

Create This Structure

text
project/
    main.py
    math_tools.py

Step 1: Create math_tools.py

Add these functions:

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

def subtract(a, b):
    return a - b

Step 2: Create main.py

Tasks:

  • Import math_tools
  • Print result of add(2, 3)
  • Print result of subtract(3, 2)

Example:

python
import math_tools

print(math_tools.add(2, 3))
print(math_tools.subtract(3, 2))

Expected Output

text
5
1

Project 2: Greeting Package

Build a package with two modules.

Create This Structure

text
app/
    greetings/
        hello.py
        bye.py
    main.py

Step 1: Create hello.py

Add:

python
def say_hello():
    print("Hello")

Step 2: Create bye.py

Add:

python
def say_bye():
    print("Goodbye")

Step 3: Create main.py

Tasks:

  • Import both functions
  • Run both functions

Example:

python
from greetings.hello import say_hello
from greetings.bye import say_bye

say_hello()
say_bye()

Expected Output

text
Hello
Goodbye

Project 3: Random Password Tool

Build a password generator.

Tasks

  • Import random
  • Create a list:
python
chars = ["A", "B", "C", "1", "2", "3", "x", "y", "z"]
  • Pick 6 random characters
  • Join them into one password
  • Print the password

Example Output

text
A2xBy3

(Output will be different each time.)


Project 4: Date App

Build a simple date tool.

Tasks

  • Import date from datetime
  • Save today’s date in a variable
  • Print the full date
  • Print only the year

Example:

python
from datetime import date

today = date.today()

print(today)
print(today.year)

Expected Output

text
2026-04-30
2026

Project 5: Setup Project Environment

Practice using tools from the terminal.

Tasks

  • Create a project folder named my_project
  • Open terminal in that folder
  • Create virtual environment:
bash
python -m venv venv
  • Activate it
  • Install requests
  • Create:
bash
pip freeze > requirements.txt

Expected Structure

text
my_project/
    venv/
    main.py
    requirements.txt

Final Challenge: Utility Toolkit

Build a multi-file project.

Create This Structure

text
toolkit/
    math_tools.py
    text_tools.py
    main.py

Step 1: Create math_tools.py

Add:

python
def double(n):
    return n * 2

def square(n):
    return n * n

Step 2: Create text_tools.py

Add:

python
def shout(text):
    return text.upper()

def count_letters(text):
    return len(text)

Step 3: Create main.py

Tasks:

  • Import all four functions
  • Print:
python
double(5)
square(5)
shout("hello")
count_letters("hello")

Expected Output

text
10
25
HELLO
5

Real World Use Case

Developers organize projects into modules and packages every day in web apps, automation tools, APIs, and data systems.


Quiz

  1. Why is math_tools.py better than putting calculator code inside one large main.py file?
  2. In Project 2, what import path is used to access say_hello() from hello.py?
  3. Why should venv be created before installing packages?
  4. What does pip freeze > requirements.txt save?
  5. In the Utility Toolkit, why are text functions and math functions placed in different files?

Assignment

Choose one project and improve it by adding at least two new features.

Examples:

  • Add multiply/divide to calculator
  • Add more greetings
  • Make password length user-controlled
  • Add reverse text tool
  • Add cube function

Summary

You practiced building organized Python projects using modules, packages, libraries, and environments with clear real-world structure.