From 445f2f4cce4af1b26cd6458efacadc8f96025594 Mon Sep 17 00:00:00 2001 From: Matt Uebel Date: Wed, 23 Oct 2024 09:43:42 -0400 Subject: [PATCH] Improve code organization and structure Rename and refactor example files, and update README. * **Refactor `example1.py`**: - Rename `presentation/examples/example1.py` to `presentation/examples/math_operations/example1.py` - Add type hints to `add`, `subtract`, `multiply`, and `divide` functions - Refactor `divide` function to handle division by zero more gracefully * **Refactor `example2.py`**: - Rename `presentation/examples/example2.py` to `presentation/examples/greetings/example2.py` - Add type hints to `greet`, `farewell`, and `main` functions - Refactor `main` function to accept a name as an argument * **Update `README.md`**: - Update paths of example code files in the `examples/` directory - Add brief description of new subdirectories `math_operations` and `greetings` --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/MattUebel/copilot-presentation?shareId=XXXX-XXXX-XXXX-XXXX). --- presentation/README.md | 11 +++++++++-- presentation/examples/{ => greetings}/example2.py | 9 ++++----- .../examples/{ => math_operations}/example1.py | 15 ++++++++------- 3 files changed, 21 insertions(+), 14 deletions(-) rename presentation/examples/{ => greetings}/example2.py (80%) rename presentation/examples/{ => math_operations}/example1.py (70%) diff --git a/presentation/README.md b/presentation/README.md index d355456..8e6e08f 100644 --- a/presentation/README.md +++ b/presentation/README.md @@ -23,8 +23,15 @@ The `presentation` directory contains the following supporting files for the pre The `examples/` directory contains the following example code files: -- `example1.py`: Demonstrates a feature of GitHub Copilot Workspace. -- `example2.py`: Demonstrates another feature of GitHub Copilot Workspace. +- `math_operations/example1.py`: Demonstrates a feature of GitHub Copilot Workspace. +- `greetings/example2.py`: Demonstrates another feature of GitHub Copilot Workspace. + +## Subdirectories + +The `examples/` directory is organized into the following subdirectories: + +- `math_operations/`: Contains example code files related to mathematical operations. +- `greetings/`: Contains example code files related to greeting messages. Feel free to modify and experiment with the example code files to better understand how GitHub Copilot Workspace can assist you in your development workflow. diff --git a/presentation/examples/example2.py b/presentation/examples/greetings/example2.py similarity index 80% rename from presentation/examples/example2.py rename to presentation/examples/greetings/example2.py index 477521d..b579fe9 100644 --- a/presentation/examples/example2.py +++ b/presentation/examples/greetings/example2.py @@ -1,24 +1,23 @@ # Example 2: Demonstrating another feature of GitHub Copilot Workspace -def greet(name): +def greet(name: str) -> str: """ Function to greet a person by name. """ return f"Hello, {name}!" -def farewell(name): +def farewell(name: str) -> str: """ Function to bid farewell to a person by name. """ return f"Goodbye, {name}!" -def main(): +def main(name: str): """ Main function to demonstrate greeting and farewell. """ - name = "Alice" print(greet(name)) print(farewell(name)) if __name__ == "__main__": - main() + main("Alice") diff --git a/presentation/examples/example1.py b/presentation/examples/math_operations/example1.py similarity index 70% rename from presentation/examples/example1.py rename to presentation/examples/math_operations/example1.py index cea1ca6..669ed8c 100644 --- a/presentation/examples/example1.py +++ b/presentation/examples/math_operations/example1.py @@ -1,30 +1,31 @@ # Example 1: Demonstrating a feature of GitHub Copilot Workspace -def add(a, b): +def add(a: float, b: float) -> float: """ Function to add two numbers. """ return a + b -def subtract(a, b): +def subtract(a: float, b: float) -> float: """ Function to subtract two numbers. """ return a - b -def multiply(a, b): +def multiply(a: float, b: float) -> float: """ Function to multiply two numbers. """ return a * b -def divide(a, b): +def divide(a: float, b: float) -> float: """ Function to divide two numbers. """ - if b == 0: - raise ValueError("Cannot divide by zero") - return a / b + try: + return a / b + except ZeroDivisionError: + return float('inf') if __name__ == "__main__": x = 10