In this exercise, you will demonstrate your understanding of Git and GitHub by forking this repository, adding a Python function, and submitting a pull request. You will write a function to calculate the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm and follow a precise workflow to manage your source code.
- Fork this repository to your own GitHub account by clicking the Fork button in the upper right corner. Note if you change the name of your repository, then you will need to use your repo name instead of
source-code-management-exercise
when following the examples below.
- Clone the forked repository to your local machine. Open your terminal and run the following command:
git clone https://github.com/<your-github-username>/source-code-management-exercise.git
- Create a new branch to work on your feature. Name your branch
<ucid>-gcd-feature
where is your student ucid (wfm8
). Example commands:cd source-code-management-exercise git checkout -b <ucid>-gcd-feature
- Inside the
students_submissions/
directory, create a new Python file namedgcd_<ucid>.py
. Replace<ucid>
with your student ucid.- Example: If your ucid is
wfm8
, name your filegcd_wfm8.py
.
- Example: If your ucid is
-
In your
gcd_<ucid>.py
file, a greatest common divisor function. Use this exact function signature:def gcd(a: int, b: int) -> int:
. DO NOT USE LOOPS in your function. Be sure to consider edge cases, like prime numbers, negative numbers, etc. Have errors print an informative message and returnNone
.def gcd(a: int, b: int) -> int: """ Calculate the greatest common divisor (GCD) of two integers a and b using the Euclidean algorithm. """ # Implement your solution here pass
-
Test your function with some basic test cases inside your file. You can use
print
statements to verify your implementation.
Example:
def gcd(a: int, b: int) -> int:
# This uses a loop, so DO NOT COPY AND PASTE this example
while b:
a, b = b, a % b
return a
# Test cases
print(gcd(54, 24)) # Expected output: 6
print(gcd(48, 18)) # Expected output: 6
print(gcd(101, 10)) # Expected output: 1
- Once your function is implemented, stage and commit your changes:
git add students_submissions/gcd_<ucid>.py git commit -m "Implemented GCD function"
- Push your changes to the
<ucid>-gcd-feature
branch in your forked repository:git push origin <ucid>-gcd-feature
- Go to your forked repository on GitHub and click the Compare & pull request button.
- Make sure to select your
<ucid>-gcd-feature
branch as the source and the original repository’smain
branch as the destination. - Submit the pull request.
When choosing repositories and branches, the GitHub screen will look something like:
base repository: [njit-prof-bill/source-code-man...][base: main] <- [head repository: iambillmccann/source-code-man...][compare: wfm8-gdc-feature]
To ensure your submission is automatically checked, you must follow these naming conventions:
- Your Python file must be placed in the
students_submissions/
directory. - The file must be named
gcd_<ucid>.py
, where<ucid>
is your actual GitHub username (e.g.,gcd_wfm8.py
). - Your file must contain a function named
gcd(a: int, b: int) -> int
.
If you do not follow these conventions, your submission will not be automatically tested, and you may be asked to resubmit.
On point for each of the following:
- Repo cloned and branched
- Create PR that will merge automatically
- Function has no loops
- Code passes basic tests
- Code passes edge cases
- Your pull request must be submitted by Sunday 2/1/2025 at 11:59.
- If you encounter any issues, feel free to reach out for help.
- Remember to test your function with a variety of inputs to ensure it works correctly.
- Follow the naming conventions carefully to avoid any issues with the automatic testing.