Quiz — Chapter 2: Setting Up Your Python Environment

Instructions: Covers setup concepts and basic Python mechanics. Answer key at end.


Multiple Choice

Q1. Which of the following is the correct command to create a virtual environment named venv?

a) python create-env venv b) virtualenv create venv c) python -m venv venv d) pip install venv


Q2. After creating a virtual environment on macOS/Linux, how do you activate it?

a) venv\Scripts\activate b) source venv/bin/activate c) python activate venv d) activate venv


Q3. What does pip freeze > requirements.txt do?

a) Installs all packages listed in requirements.txt b) Saves the currently installed packages and their versions to requirements.txt c) Upgrades all installed packages to their latest versions d) Lists all available packages on PyPI


Q4. What is PyPI?

a) Python's built-in testing framework b) A version of Python for scientific computing c) The Python Package Index — where pip downloads packages from d) Python's Interactive Interface (the REPL)


Q5. Which editor feature helps you catch syntax errors before running your code?

a) The REPL b) IntelliSense / inline error detection c) The virtual environment d) The requirements.txt file


Q6. What does the (venv) prefix in your terminal prompt mean?

a) You are inside the venv folder b) The virtual environment is activated and packages install here c) Python has been successfully installed d) You are in the Python REPL


Q7. When is Jupyter Notebook most appropriate vs. a .py script?

a) Jupyter for automated scripts that run unattended; scripts for analysis b) Jupyter for data exploration and interactive analysis; scripts for automation and production c) They are equivalent — use whichever you prefer d) Jupyter is better for beginners; scripts for advanced users


Q8. A colleague installed numpy when they meant to install pandas. Which command removes numpy?

a) pip delete numpy b) pip remove numpy c) pip uninstall numpy d) python -m remove numpy


Q9. You install pandas in your terminal, then try import pandas in VS Code and get ModuleNotFoundError. The most likely cause is:

a) pandas was installed incorrectly b) You need to restart your computer after installation c) VS Code is using a different Python interpreter than your terminal d) pandas is not compatible with your Python version


Q10. What is the Python REPL?

a) A specialized IDE for Python development b) An interactive mode where Python expressions are evaluated immediately as you type c) A Python testing framework d) A way to compile Python to native machine code


True or False

Q11. On macOS, you should use the system Python (pre-installed with the OS) for your projects.

Q12. Virtual environments can be shared between projects — one environment can serve multiple projects.

Q13. When you close and reopen VS Code, you need to manually reactivate your virtual environment in the terminal.

Q14. pip list shows all installed packages in the currently active environment.

Q15. Python code files use the .py extension.

Q16. In the Python REPL, you must use print() to see the result of an expression.

Q17. The .pyc files in __pycache__/ are created automatically by Python and you should not delete or modify them manually.

Q18. Anaconda and pip/venv are mutually exclusive — you must choose one and cannot switch.

Q19. pip install -r requirements.txt installs all packages listed in that file.

Q20. You can run Jupyter Notebook without having Jupyter installed, as it comes with Python by default.


Short Answer

Q21. Explain what happens if you forget to activate your virtual environment before installing a package.

Q22. What is the difference between pip install pandas and pip install -r requirements.txt?

Q23. In the hello_business.py example, what does ${annual_revenue:,.0f} produce, and what does each formatting element (:, ,, .0, f) mean?

Q24. Why does the chapter recommend against using sudo pip install on macOS/Linux?


Applied

Q25. You're setting up a new Python project for tracking Maya's client invoices. Walk through the complete setup process from "empty folder" to "ready to write code." Include every command and any decisions you'd need to make.


Answer Key

Multiple Choice: Q1: c | Q2: b | Q3: b | Q4: c | Q5: b | Q6: b | Q7: b | Q8: c | Q9: c | Q10: b

True or False: Q11: False (use the python.org-installed Python) Q12: False (one environment per project is the best practice) Q13: It depends — VS Code often auto-activates when detecting a venv folder, but the behavior varies Q14: True Q15: True Q16: False — in the REPL, expressions print automatically (you only need print() for explicit output in scripts) Q17: True (Python manages these; deleting them is safe but unnecessary) Q18: False — you can use pip within conda environments; they can coexist Q19: True Q20: False — Jupyter must be installed separately with pip install jupyter

Short Answer — Sample Responses:

Q21: The package installs into the global Python installation instead of the project environment. This can cause version conflicts with other projects and means your project's dependencies aren't isolated or documented.

Q22: pip install pandas installs one specific package. pip install -r requirements.txt installs all packages listed in the file, including specific versions — used to recreate an environment exactly.

Q23: $15,400,000 (or similar). The : starts the format spec; , adds comma separators; .0 means zero decimal places; f means format as a floating-point number.

Q24: sudo pip install modifies the system Python installation, which macOS uses internally. Modifying it can break system behavior and is difficult to undo. Virtual environments eliminate the need for it.

Applied (Q25 — Sample):

mkdir maya-invoicing && cd maya-invoicing
python3 -m venv venv
source venv/bin/activate      # (or venv\Scripts\activate on Windows)
pip install pandas openpyxl   # (and others as needed)
pip freeze > requirements.txt
code .                         # Open VS Code in this folder

Then create the first .py file in VS Code.