Practice Bank: Professional Python
A deeper set of practice problems, organized by topic, for extra reps beyond the main exercises — including scenario-based problems written in the same style you'll meet in real interviews. This chapter covers venv, project structure, logging, argparse, packaging basics, and shipping a real CLI tool.
starter.py below and run
python3 starter.py from inside the same folder. Standard
library only — nothing to install.
Topic 1: Virtual Environments
1 Is a venv active?
Find # TODO 1.1. Write is_running_in_venv(sys_prefix, sys_base_prefix).
2 Parse pip freeze output
Find # TODO 1.2. Write parse_pip_freeze(freeze_output).
3 Debug the Code
Find # TODO 1.3. This wrongly claims global installs have no downsides for team projects. Fix it.
Comparing Two Approaches
Find # TODO 1.A. Write recommended_venv_command(venv_already_exists).
Why venv per project
Find # TODO 1.B. Write explain_why_venv_per_project().
Topic 2: Project Structure
1 Minimal professional layout
Find # TODO 2.1. Write has_required_layout(file_paths).
2 Does a directory need __init__.py?
Find # TODO 2.2. Write needs_init_file(directory_contains_python_files, uses_namespace_package).
3 Debug the Code
Find # TODO 2.3. This wrongly claims tests should live mixed in with source, no separate folder. Fix it.
Comparing Two Approaches
Find # TODO 2.A. Write choose_layout(package_will_be_published_to_pypi).
Why structure matters on a team
Find # TODO 2.B. Write explain_why_structure_matters().
Topic 3: Logging
1 Level number to name
Find # TODO 3.1. Write level_name_for_number(level_number).
2 Would this message be emitted?
Find # TODO 3.2. Write would_message_be_emitted(logger_level, message_level).
3 Debug the Code
Find # TODO 3.3. This log format string has fields out of order and a typo. Fix it.
4 The root logger's default level
Find # TODO 3.4. Write default_root_level().
5 Count emitted messages
Find # TODO 3.5. Write count_emitted_messages(logger_level, message_levels).
Comparing Two Approaches
Find # TODO 3.A. Write choose_log_level_for_environment(is_production).
Silent production failures
Find # TODO 3.B. Write explain_why_silent_failure_needs_logging().
Topic 4: argparse
1 Counting parser arguments
Find # TODO 4.1. Write build_parser_arg_count(positional_names, optional_flag_names).
2 Parse real greeting args
Find # TODO 4.2. Write parse_greeting_args(argv) using a real argparse.ArgumentParser.
3 Debug the Code
Find # TODO 4.3. This wrongly claims every argument is optional by default. Fix it.
4 Exit code for a missing required arg
Find # TODO 4.4. Write exit_code_for_missing_required_arg().
5 A count-style flag
Find # TODO 4.5. Write build_count_flag_value(argv) using a real argparse.ArgumentParser with action="count".
Comparing Two Approaches
Find # TODO 4.A. Write choose_argparse_action(flag_takes_a_value).
argparse vs. manual sys.argv
Find # TODO 4.B. Write explain_argparse_vs_manual_sys_argv().
Topic 5: Packaging Basics (pyproject.toml)
1 Minimum required fields
Find # TODO 5.1. Write has_minimum_pyproject_fields(toml_keys).
2 Classify a dependency pin style
Find # TODO 5.2. Write dependency_pin_style(version_spec).
3 Debug the Code
Find # TODO 5.3. This wrongly claims pyproject.toml has no real effect on installing the package. Fix it.
Comparing Two Approaches
Find # TODO 5.A. Write choose_dependency_pin(library_is_your_own_stable_api, library_changes_often).
Why pin dependencies
Find # TODO 5.B. Write explain_why_pin_dependencies().
Topic 6: Putting It Together — A Shippable CLI Tool
1 Minimum files to ship
Find # TODO 6.1. Write minimum_files_for_shippable_cli(file_names).
2 Build an entry-point line
Find # TODO 6.2. Write cli_entry_point_line(package_name, module_name, function_name).
3 Debug the Code
Find # TODO 6.3. This wrongly claims pip install -e . behaves like a normal install. Fix it.
Comparing Two Approaches
Find # TODO 6.A. Write choose_install_mode(actively_developing_the_package).
The shippable checklist
Find # TODO 6.B. Write explain_shippable_checklist().
solution.py. Your exact
wording doesn't need to match on the explanation-style tasks
— the goal is that your program runs without errors and does
what each TODO asks. Every data-driven and real-Python task's output
is exactly reproducible.