Day 3 Quiz & Exercises#

TDS Bridge Bootcamp — VS Code + Python Projects with uv#

Instructions: Attempt MCQs first, then do the exercises in order in your terminal.


Part A — 20 Multiple Choice Questions#

Q1. You run pip install pandas without a virtual environment. A week later you start a new project that needs a different version of pandas. What is the likely problem?

  • A) pip won’t allow installing pandas twice
  • B) Both projects share the same global pandas — changing the version for one breaks the other
  • C) pip automatically creates separate environments per project
  • D) You’ll need to uninstall Python and reinstall it
Answer

B — Both projects share the same global pandas — changing the version for one breaks the other


Q2. What does uv init myproject do?

  • A) Installs Python inside a folder called myproject
  • B) Creates a new project folder with pyproject.toml and a starter structure
  • C) Initialises a Git repository called myproject
  • D) Downloads myproject from PyPI
Answer

Buv init scaffolds a project with pyproject.toml


Q3. After running uv add requests, where are the installed files stored?

  • A) Globally in /usr/local/lib/python/
  • B) In a .venv/ folder inside your project
  • C) In ~/.local/share/uv/packages/
  • D) In the pyproject.toml file directly
Answer

B — uv installs into the project-local .venv/


Q4. What is the purpose of uv.lock?

  • A) Prevents other users from modifying your project
  • B) Records the exact versions of all packages so anyone can recreate the same environment
  • C) Locks the Python version permanently
  • D) Stores your API keys securely
Answer

B — Lock file freezes exact versions for reproducibility


Q5. A teammate clones your project and wants to install all the dependencies. Which command should they run?

  • A) pip install -r requirements.txt
  • B) uv install
  • C) uv sync
  • D) uv add --all
Answer

Cuv sync installs everything from pyproject.toml + lock


Q6. What is pyproject.toml used for?

  • A) Running your Python script
  • B) Storing project metadata and the list of dependencies
  • C) Configuring VS Code settings
  • D) Replacing your .bashrc for Python projects
Answer

Bpyproject.toml = project config + dependency list


Q7. You run uv run main.py. What happens?

  • A) uv uploads main.py to a remote server and runs it there
  • B) uv activates the project’s virtual environment and runs main.py inside it
  • C) uv installs main.py as a system command
  • D) uv creates a new file called main.py and opens it
Answer

Buv run uses the project’s .venv automatically


Q8. What is the difference between uv run script.py and activating the venv manually then running python script.py?

  • A) uv run is slower because it does extra setup
  • B) The end result is the same — uv run just handles the activation for you automatically
  • C) uv run uses a different Python than the virtual environment
  • D) You must manually activate the venv first, then use uv run
Answer

B — Same result; uv run just saves you the activate step


Q9. In VS Code, how do you open the Command Palette?

  • A) Ctrl+P
  • B) Ctrl+Shift+P
  • C) Ctrl+Alt+P
  • D) F1+P
Answer

BCtrl+Shift+P opens the VS Code Command Palette


Q10. You’ve created a uv project but VS Code keeps using the wrong Python. What should you do?

  • A) Reinstall VS Code
  • B) Open Command Palette → “Python: Select Interpreter” → choose the .venv path
  • C) Delete .venv and reinstall packages
  • D) Add python = ".venv" to pyproject.toml
Answer

B — Select Interpreter tells VS Code which Python to use


Q11. What does the VS Code shortcut Ctrl+Shift+F do?

  • A) Format the current file
  • B) Find and replace in the current file only
  • C) Search for text across all files in the project
  • D) Open a new terminal
Answer

CCtrl+Shift+F = project-wide search


Q12. Which VS Code extension provides type checking and fast autocompletion for Python?

  • A) Black
  • B) Pylance
  • C) Ruff
  • D) Jupyter
Answer

B — Pylance provides IntelliSense and type checking


Q13. You’re exploring a dataset for the first time — trying different filters, plotting, printing shapes. Which file type is more appropriate?

  • A) A .py script, because it’s faster
  • B) A .ipynb notebook, because you want to run code cell by cell and see output interactively
  • C) A .toml file, because it’s more structured
  • D) A .sh script, because Python is too slow for data exploration
Answer

B — Notebooks are ideal for interactive exploration


Q14. You’ve finished exploring data in a notebook and want to turn your cleaning code into something you can run every day automatically. What should you do?

  • A) Keep using the notebook — just run all cells every day
  • B) Move the code into a .py script that can be run from the terminal
  • C) Convert the notebook to a .toml file
  • D) Upload the notebook to GitHub and run it from there
Answer

B — Scripts are repeatable, testable, and automatable


Q15. What does the source .venv/bin/activate command do? (Method B)

  • A) Installs packages into the virtual environment
  • B) Creates the virtual environment
  • C) Activates the virtual environment so python and pip point to it
  • D) Deletes the virtual environment
Answer

Cactivate redirects python and pip to the venv


Q16. After activating a virtual environment, your terminal prompt changes to show (venv) at the start. You then run pip install flask. Where does Flask get installed?

  • A) Globally, because pip ignores the venv
  • B) Into the active virtual environment only
  • C) In the pyproject.toml file
  • D) Into ~/.local/lib/
Answer

B — Packages go into the active venv when it’s activated


Q17. Which uv command removes a package from your project?

  • A) uv delete requests
  • B) uv uninstall requests
  • C) uv remove requests
  • D) uv pip uninstall requests
Answer

Cuv remove <package> removes it from the project


Q18. What does uv venv create?

  • A) A new project with pyproject.toml
  • B) A plain virtual environment folder (.venv/) without a full project structure
  • C) A virtual machine
  • D) A GitHub repository
Answer

Buv venv = plain venv, no project structure


Q19. A friend gives you a project folder. It has pyproject.toml and uv.lock but no .venv/. What is the first command you should run?

  • A) uv init
  • B) uv add
  • C) uv sync
  • D) python -m venv .venv
Answer

Cuv sync recreates .venv/ from the lock file


Q20. Which of these is true about .venv/?

  • A) It should be committed to Git so teammates can use it
  • B) It is listed in .gitignore because it can be recreated from pyproject.toml — no need to share it
  • C) It contains your source code
  • D) It is required to run uv init
Answer

B.venv/ is regenerable — never commit it to Git


Q21. Which command updates uv to the latest version?

  • A) uv update
  • B) uv self update
  • C) uv upgrade
  • D) pip install --upgrade uv
Answer

Buv self update is the built-in update mechanism.


Q22. When you run uv add pandas, what happens to pyproject.toml?

  • A) It is deleted
  • B) pandas is added to the dependencies list
  • C) It is backed up as pyproject.bak
  • D) Nothing, it only affects uv.lock
Answer

Buv add updates pyproject.toml and then uv.lock.


Q23. How do you run a specific Python script, like test.py, using uv?

  • A) uv test.py
  • B) uv execute test.py
  • C) uv run test.py
  • D) uv python test.py
Answer

Cuv run executes a script using the project’s environment.


Q24. What is the benefit of a .ipynb file over a .py file?

  • A) It runs much faster
  • B) It can mix markdown text, code, and inline visualizations
  • C) It is smaller in size
  • D) It doesn’t require Python to run
Answer

B — Notebooks are interactive and support markdown and outputs.


Q25. If you want to use a virtual environment without a pyproject.toml, which command do you use?

  • A) uv init
  • B) uv venv
  • C) uv add
  • D) uv sync
Answer

Buv venv creates a raw .venv folder.


Q26. Where is the temporary virtual environment created when you run a script with uv run --with pandas script.py?

  • A) In .venv
  • B) In a global temporary cache managed by uv
  • C) In the current directory as temp_venv
  • D) In /tmp/
Answer

Buv creates temporary, cached environments for ad-hoc scripts.


Q27. Why should you NOT run pip install package globally using sudo?

  • A) It makes Python slower
  • B) It can break system-level tools that rely on specific package versions
  • C) It consumes too much disk space
  • D) pip doesn’t support sudo
Answer

B — Modifying global system packages can break the OS.


Q28. In VS Code, how do you verify you are using the correct Python interpreter?

  • A) Check the bottom-right corner of the status bar
  • B) Open settings and search for Python
  • C) You have to run a script to find out
  • D) It always uses the global Python
Answer

A — The selected interpreter is shown in the status bar.


Q29. What is the purpose of uv sync?

  • A) Uploads your code to GitHub
  • B) Syncs the .venv to perfectly match uv.lock
  • C) Formats your Python files
  • D) Deletes unused variables
Answer

Buv sync ensures your environment matches the lockfile exactly.


Q30. Can uv manage Python versions itself?

  • A) Yes, uv python install can install different Python versions
  • B) No, you must install Python separately
  • C) Yes, but only on Windows
  • D) No, uv only manages packages, not Python
Answer

Auv has built-in Python version management.


Full Answer Key (spoilers)
QAnswer
1B
2B
3B
4B
5C
6B
7B
8B
9B
10B
11C
12B
13B
14B
15C
16B
17C
18B
19C
20B
21B
22B
23C
24B
25B
26B
27B
28A
29B
30A

Part B — Terminal Exercises#

All exercises use the terminal and VS Code. Do them in order.


Exercise 1 — Create a project and add packages#

cd ~/tds/bootcamp
uv init day3-practice
cd day3-practice

Now add two packages:

uv add requests pandas

Verify:

cat pyproject.toml    # Are requests and pandas listed?
ls -la                # Do you see .venv/ and uv.lock?

Write down: What exact versions of requests and pandas were installed? (Check uv.lock)


Exercise 2 — Write and run a script#

Create a file main.py in your project:

# main.py
import requests
import pandas as pd

# Fetch some JSON data
response = requests.get("https://jsonplaceholder.typicode.com/users")
users = response.json()

# Put it in a DataFrame
df = pd.DataFrame(users)[["id", "name", "email", "phone"]]

# Sort by name
df = df.sort_values("name")

print(df.to_string(index=False))

Run it:

uv run main.py

Expected: A sorted table of 10 fake users printed to the terminal.

Question: What happens if you run python main.py instead of uv run main.py? Try it and explain why.


Exercise 3 — Open in VS Code and select the interpreter#

code .

Inside VS Code:

  1. Open main.py
  2. Press Ctrl+Shift+P → type Python: Select Interpreter
  3. Choose the one with .venv in the path
  4. Hover over pd or requests in the code — does VS Code show you the type info?
  5. Press Ctrl+` to open the integrated terminal and run uv run main.py from there

Exercise 4 — Understand what uv.lock does#

# See the lockfile
cat uv.lock | head -30

Now simulate what a teammate would do after cloning your project:

# Delete the .venv to simulate a fresh clone
rm -rf .venv

# Restore everything from the lockfile
uv sync

# Confirm it works
uv run main.py

Confirm: Does the script still work after uv sync? That’s reproducibility.


Exercise 5 — Script vs Notebook comparison#

  1. In VS Code, create a new file called explore.ipynb
  2. VS Code will open it as a Jupyter notebook
  3. Add a cell with:
import pandas as pd
df = pd.DataFrame({"name": ["Alice", "Bob", "Charlie"], "score": [88, 92, 75]})
df.sort_values("score", ascending=False)
  1. Run the cell — you see the output inline

Reflect and write in day3.md: What can you do in the notebook that you can’t do as easily in main.py? What can main.py do that the notebook can’t?


End of Day 3 Quiz & Exercises

Exercise 6 — Additional Practice#

  1. Try installing a new Python version using uv python install 3.11.
  2. Create a temporary script hello.py that imports requests and prints requests.__version__.
  3. Run it using uv run --with requests hello.py.

Question to answer: Did uv create a pyproject.toml or .venv in your folder for this script? Why is this useful?