Student Activity

Student Activity Guide:

1) Creating and Using Modules

  • Write a Python module that contains a simple function.

  • Import the module in another script and use the function.

Example Code:

my_module.py

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

main.py

import my_module
print(my_module.greet("Alice"))

Student Exercise: Create a module with multiple functions and import it in another script.

2) Importing and Using Built-in Modules

  • Explore Python's built-in modules like math and random.

  • Use the datetime module to display the current date and time.

Example Code:

Student Exercise: Use the os module to list all files in a directory.

3) Structuring Python Projects with Packages

  • Create a package with multiple modules and use them.

  • Organize project files into logical directories.

Example Code:

project/

module1.py

module2.py

main.py

Student Exercise: Create a Python package with two modules and import functions from them.

4) Virtual Environments and Dependency Management

  • Set up a virtual environment using venv.

  • Install and manage dependencies using pip.

Example Code:

Student Exercise: Create a virtual environment, install some packages, and generate a requirements.txt file.

Last updated