From 230f7cdae22710721393cbb325dbf7785eff14b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=9A=D1=83=D1=82?= =?UTF-8?q?=D0=BB=D0=B0=D1=85=D0=BC=D0=B5=D1=82=D0=BE=D0=B2?= Date: Tue, 26 May 2026 13:18:13 +0000 Subject: [PATCH] add main.py --- main.py | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..83b4374 --- /dev/null +++ b/main.py @@ -0,0 +1,106 @@ +""" +Main entry point for the AI Fluency Plan project. + +This script demonstrates how to load and display a personal AI fluency plan that is stored in ``plan.txt``. +It also provides three example usages: +1. Print the entire plan. +2. Show only the first 5 lines of the plan. +3. Count the number of words in the plan. + +The goal of this repository is to showcase a simple, well‑structured Python project that can be used as a template for future assignments. +""" + +from __future__ import annotations + +import os +from pathlib import Path +from typing import List + +# --------------------------------------------------------------------------- +# Utility functions +# --------------------------------------------------------------------------- + +def read_plan_file(plan_path: str | Path) -> str: + """Return the full text of the plan file. + + Parameters + ---------- + plan_path: + Path to ``plan.txt``. The function accepts either a string or a + :class:`pathlib.Path` instance. + + Returns + ------- + str + Raw contents of the plan file. + """ + path = Path(plan_path) + if not path.exists(): + raise FileNotFoundError(f"Plan file {plan_path!s} does not exist") + return path.read_text(encoding="utf-8") + + +def get_first_n_lines(text: str, n: int) -> List[str]: + """Return the first *n* lines of a multiline string. + + Parameters + ---------- + text: + Multiline string to split. + n: + Number of lines to return. + + Returns + ------- + list[str] + List containing up to ``n`` lines. + """ + return text.splitlines()[:n] + + +def count_words(text: str) -> int: + """Return the number of words in *text*. + + Words are split on whitespace. Empty strings are ignored. + """ + return len([w for w in text.split() if w]) + +# --------------------------------------------------------------------------- +# Main logic +# --------------------------------------------------------------------------- + +def main() -> None: + """Demonstrate the three example usages of the plan loader. + + The function prints output to stdout. It is intentionally simple so + that it can be run in any environment without external dependencies. + """ + plan_path = Path(__file__).parent / "plan.txt" + try: + full_plan = read_plan_file(plan_path) + except FileNotFoundError as exc: + print(exc) + return + + # Example 1: Print the entire plan. + print("\n=== Full AI Fluency Plan ===") + print(full_plan) + + # Example 2: Show only the first five lines. + print("\n=== First 5 lines of the plan ===") + for line in get_first_n_lines(full_plan, 5): + print(line) + + # Example 3: Count words. + word_count = count_words(full_plan) + print(f"\nWord count: {word_count}") + +# --------------------------------------------------------------------------- +# Entry point guard +# --------------------------------------------------------------------------- +if __name__ == "__main__": + main() + +# --------------------------------------------------------------------------- +# End of file +# ---------------------------------------------------------------------------