Chapter 3 Quiz: Python Environment Setup
Instructions
This quiz tests your understanding of Python environment setup concepts covered in Chapter 3. Answer all questions to the best of your ability. Each question is worth 1 point unless otherwise noted.
Time Limit: 45 minutes Total Points: 30
Section A: Python Installation (Questions 1-6)
Question 1
What is the recommended minimum Python version for this textbook's basketball analytics projects?
A) Python 2.7 B) Python 3.6 C) Python 3.10 D) Python 4.0
Question 2
When installing Python on Windows, which option is critical to enable for command-line usage?
A) Install for all users B) Add Python to PATH C) Install pip D) Enable debugging symbols
Question 3
Which command correctly displays the version of Python installed on your system?
A) python -v
B) python --version
C) python -version
D) python version
Question 4
What is PyPI?
A) A Python IDE B) The Python Package Index, a repository of Python packages C) A Python testing framework D) The Python Programming Interface
Question 5
On macOS, which package manager is recommended for installing Python?
A) apt B) yum C) Homebrew D) Chocolatey
Question 6
Which of the following is NOT a valid reason to use Python 3 over Python 2?
A) Python 2 reached end of life in January 2020 B) Python 3 has better Unicode support C) Python 3 runs faster than Python 2 in all cases D) All new packages are developed for Python 3
Section B: Package Managers (Questions 7-12)
Question 7
What is the correct pip command to install a specific version of pandas (version 2.0.3)?
A) pip install pandas version 2.0.3
B) pip install pandas@2.0.3
C) pip install pandas==2.0.3
D) pip install pandas -v 2.0.3
Question 8
Which command installs all packages listed in a requirements.txt file?
A) pip install requirements.txt
B) pip install -r requirements.txt
C) pip requirements.txt install
D) pip --requirements requirements.txt
Question 9
What is a primary advantage of Conda over pip?
A) Conda only installs Python packages B) Conda can manage non-Python dependencies C) Conda is faster for all installations D) Conda only works on Windows
Question 10
Which command creates a new Conda environment named "nba_analysis" with Python 3.11?
A) conda new nba_analysis python=3.11
B) conda create --name nba_analysis python=3.11
C) conda environment create nba_analysis python=3.11
D) conda create nba_analysis --python 3.11
Question 11
What does the command pip freeze > requirements.txt do?
A) Installs frozen packages from requirements.txt B) Removes all installed packages C) Exports currently installed packages and versions to requirements.txt D) Checks if requirements.txt is valid
Question 12
Which channel is commonly used with Conda for additional scientific computing packages?
A) pip-forge B) conda-forge C) python-forge D) science-forge
Section C: Essential Libraries (Questions 13-17)
Question 13
Match each library with its primary purpose. (2 points)
| Library | Purpose |
|---|---|
| 1. pandas | A. Machine learning |
| 2. numpy | B. Statistical visualization |
| 3. matplotlib | C. Data manipulation |
| 4. scikit-learn | D. Numerical computing |
| 5. seaborn | E. Basic plotting |
Question 14
Which library provides the DataFrame data structure commonly used for tabular basketball statistics?
A) numpy B) matplotlib C) pandas D) scipy
Question 15
What is the correct import statement for using scikit-learn's linear regression model?
A) from sklearn import LinearRegression
B) from sklearn.linear_model import LinearRegression
C) import sklearn.LinearRegression
D) from scikit_learn import LinearRegression
Question 16
Which library would you primarily use to create a box plot showing scoring distribution by position?
A) numpy B) scipy C) seaborn D) pandas
Question 17
Statsmodels differs from scikit-learn primarily because it:
A) Cannot perform regression B) Provides detailed statistical output and hypothesis testing C) Is faster for large datasets D) Only works in Jupyter notebooks
Section D: Jupyter Notebooks (Questions 18-22)
Question 18
What keyboard shortcut runs a cell and moves to the next cell in Jupyter Notebook?
A) Ctrl + Enter B) Shift + Enter C) Alt + Enter D) Tab + Enter
Question 19
Which Jupyter magic command is used to display matplotlib plots inline?
A) %plot inline
B) %matplotlib inline
C) %display plots
D) %inline matplotlib
Question 20
What is the correct command to start JupyterLab from the terminal?
A) jupyter notebook
B) jupyter start
C) jupyter lab
D) jupyterlab start
Question 21
In Jupyter Notebook command mode, which key converts a code cell to a markdown cell?
A) C B) M C) T D) X
Question 22
Which of the following is a best practice for Jupyter notebooks?
A) Put all imports at the bottom of the notebook B) Avoid using markdown cells to keep notebooks concise C) Restart kernel and run all cells before sharing D) Use single-letter variable names for faster typing
Section E: Version Control (Questions 23-26)
Question 23
Which command initializes a new Git repository in the current directory?
A) git start
B) git init
C) git new
D) git create
Question 24
What is the purpose of a .gitignore file?
A) To store Git configuration settings B) To specify files and folders Git should not track C) To list all commits in the repository D) To define branch naming rules
Question 25
Which sequence of commands correctly stages all changes and creates a commit?
A) git commit -m "message" then git add .
B) git add . then git commit -m "message"
C) git stage . then git save -m "message"
D) git push then git commit
Question 26
What should you NEVER commit to a Git repository?
A) Python source code B) requirements.txt files C) API keys and passwords D) Jupyter notebooks
Section F: Virtual Environments (Questions 27-30)
Question 27
What is the primary purpose of a virtual environment?
A) To make Python run faster B) To isolate project dependencies from other projects C) To encrypt Python code D) To enable remote development
Question 28
Which command creates a virtual environment using Python's built-in venv module?
A) python -m virtualenv venv
B) python -m venv venv
C) python --create-venv venv
D) venv create venv
Question 29
On Windows, which command activates a virtual environment named "venv"?
A) source venv/bin/activate
B) venv\Scripts\activate
C) activate venv
D) python -m activate venv
Question 30
Which file should be included in .gitignore to prevent committing virtual environment files?
A) requirements.txt
B) venv/
C) *.py
D) .git/
Bonus Questions (2 points each)
Bonus Question 1
Explain the difference between pip install package and pip install -e . (editable install). When would you use each?
Bonus Question 2
Your colleague sends you a Conda environment.yml file, but you prefer using pip with virtual environments. Describe the steps you would take to recreate a similar environment using pip and venv.
Answer Key
Section A: Python Installation
-
C) Python 3.10 - Python 3.10 and 3.11 provide the best balance of compatibility and modern features for data science work.
-
B) Add Python to PATH - This allows you to run Python from any command prompt location without specifying the full path.
-
B)
python --version- The double-dash format--versionis the standard way to check version information. -
B) The Python Package Index, a repository of Python packages - PyPI (pypi.org) hosts over 400,000 Python packages that can be installed with pip.
-
C) Homebrew - Homebrew is the most popular package manager for macOS and simplifies Python installation and updates.
-
C) Python 3 runs faster than Python 2 in all cases - This is not universally true; performance varies by use case. The other statements are valid reasons.
Section B: Package Managers
-
C)
pip install pandas==2.0.3- The double equals sign specifies an exact version requirement. -
B)
pip install -r requirements.txt- The-rflag tells pip to read requirements from the specified file. -
B) Conda can manage non-Python dependencies - Conda can install system-level libraries, compilers, and other non-Python software.
-
B)
conda create --name nba_analysis python=3.11- The
--nameflag specifies the environment name, followed by package specifications.
- The
-
C) Exports currently installed packages and versions to requirements.txt
pip freezelists all installed packages with exact versions, and>redirects to a file.
-
B) conda-forge
- conda-forge is a community-maintained channel with a wide variety of packages.
Section C: Essential Libraries
-
Answers: 1-C, 2-D, 3-E, 4-A, 5-B (2 points)
- pandas: Data manipulation (DataFrames)
- numpy: Numerical computing (arrays, math)
- matplotlib: Basic plotting (foundation library)
- scikit-learn: Machine learning (models, preprocessing)
- seaborn: Statistical visualization (built on matplotlib)
-
C) pandas
- pandas provides the DataFrame class, essential for working with tabular sports data.
-
B)
from sklearn.linear_model import LinearRegression- scikit-learn uses a modular structure where models are in submodules like
linear_model.
- scikit-learn uses a modular structure where models are in submodules like
-
C) seaborn
- seaborn's
boxplot()function creates statistical box plots with minimal code.
- seaborn's
-
B) Provides detailed statistical output and hypothesis testing
- Statsmodels produces comprehensive statistical summaries, p-values, and confidence intervals.
Section D: Jupyter Notebooks
-
B) Shift + Enter
- Shift + Enter executes the current cell and moves to the next; Ctrl + Enter stays in place.
-
B)
%matplotlib inline- This magic command configures matplotlib to display plots directly in the notebook.
-
C)
jupyter lab- JupyterLab is started with the
jupyter labcommand.
- JupyterLab is started with the
-
B) M
- In command mode, 'M' changes a cell to markdown; 'Y' changes it back to code.
-
C) Restart kernel and run all cells before sharing
- This ensures the notebook runs correctly from start to finish, verifying reproducibility.
Section E: Version Control
-
B)
git initgit initcreates a new .git directory and initializes the repository.
-
B) To specify files and folders Git should not track
- The .gitignore file uses patterns to exclude files from version control.
-
B)
git add .thengit commit -m "message"- Files must be staged (added) before they can be committed.
-
C) API keys and passwords
- Credentials should never be in version control; use environment variables or secret managers.
Section F: Virtual Environments
-
B) To isolate project dependencies from other projects
- Virtual environments prevent package conflicts between projects with different requirements.
-
B)
python -m venv venv- The
-m venvruns the venv module, and the second "venv" is the directory name.
- The
-
B)
venv\Scripts\activate- Windows uses backslashes and the Scripts folder; macOS/Linux use forward slashes and bin.
-
B)
venv/- The virtual environment folder contains local copies of packages and should not be committed.
Bonus Questions
Bonus 1: (2 points)
- pip install package installs a package from PyPI to your environment
- pip install -e . installs the current directory in "editable" mode, creating a link so changes to source code are immediately reflected without reinstalling
- Use regular install for dependencies; use editable install for packages you're actively developing
Bonus 2: (2 points)
Steps to convert from Conda to pip:
1. Read the environment.yml file to identify dependencies
2. Create a new directory and virtual environment: python -m venv venv
3. Activate the environment: venv\Scripts\activate (Windows) or source venv/bin/activate (Unix)
4. Create a requirements.txt file with the packages from environment.yml (adjusting names if they differ between conda and pip)
5. Install with pip install -r requirements.txt
6. Note: Some conda packages may not have pip equivalents, requiring alternative solutions
Scoring Guide
| Score | Grade | Feedback |
|---|---|---|
| 28-34 | A | Excellent understanding of Python environment setup |
| 24-27 | B | Good grasp of core concepts; review weak areas |
| 20-23 | C | Adequate understanding; more practice recommended |
| 16-19 | D | Review chapter material and redo exercises |
| Below 16 | F | Seek additional help; review fundamentals |
Post-Quiz Reflection
After completing this quiz, consider:
- Which sections did you find most challenging?
- What concepts need additional review?
- How will you apply these skills in your basketball analytics projects?
Take time to revisit sections where you scored below 80% before moving to the next chapter.