Editor

Predict the Environment Check

Intermediate · Predict the output · from Python Virtual Environments and pip: A Practical Guide

From the lesson: Python Virtual Environments and pip: A Practical Guide

Imagine you're a carpenter working on two different projects. One needs tiny finishing nails and the other needs heavy-duty bolts. You wouldn't dump all your hardware into one toolbox - you'd have separate toolboxes so the right parts are always ready for the right job.

Read the lesson

Read the code carefully and predict the output. The code simulates checking which virtual environment is active and what packages are available.

environments = {
'global': ['pip', 'setuptools'],
'project_a': ['pip', 'setuptools', 'flask', 'requests'],
'project_b': ['pip', 'setuptools', 'django', 'celery'],
}
active_env = 'project_a'
def is_available(package):
return package in environments[active_env]
packages_to_check = ['flask', 'django', 'requests', 'pip']
for pkg in packages_to_check:
status = 'installed' if is_available(pkg) else 'not found'
print(f'{pkg}: {status}')

More Virtual Environment exercises

All Python exercises · 50 practice problems · Modules & Packaging quiz