Assignment Unit 4 Submit
Assignment Unit 4 Submit
Part 1
As a software developer, I have been tasked with developing a function that calculates the
hypotenuse of a right triangle using the Pythagorean theorem. I will implement this using an
incremental development approach, where I build the function step by step while ensuring
correctness at each stage.
Output
```
5.0
13.0
17.0
```
---
Part 2
For my portfolio, I will create a **personal finance tracker** that helps users manage income and
expenses. The development will follow an **incremental approach**, ensuring that each stage is
functional and thoroughly tested.
```python
def initialize_tracker():
return {'income': [], 'expenses': []}
```
```python
def add_income(tracker, amount, description):
tracker['income'].append({'amount': amount, 'description': description})
```python
def calculate_balance(tracker):
total_income = sum(item['amount'] for item in tracker['income'])
total_expenses = sum(item['amount'] for item in tracker['expenses'])
return total_income - total_expenses
```
def get_expenses_by_category(tracker):
expenses_by_category = {}
for expense in tracker['expenses']:
category = expense.get('category', 'Uncategorized')
expenses_by_category.setdefault(category, []).append(expense)
return expenses_by_category
```
```python
# Initializing tracker
tracker = initialize_tracker()
# Displaying results
print("********** Personal Finance Tracker **********")
print("Current Balance: ${:.2f}".format(calculate_balance(tracker)))
print("\nIncome:")
for entry in tracker['income']:
print(f"- {entry['description']}: ${entry['amount']:.2f}")
print("\nExpenses by Category:")
expenses_by_category = get_expenses_by_category(tracker)
for category, expenses in expenses_by_category.items():
print(f"- Category: {category}")
for expense in expenses:
print(f" - {expense['description']}: ${expense['amount']:.2f}")
```
Output
Conclusion
This assignment demonstrates the incremental development approach by breaking the
problem into smaller, manageable parts, ensuring correctness at each stage.
- In Part 1 I developed and tested a function to calculate the hypotenuse of a right triangle.
- In Part 2 I created a personal finance tracker that allows users to record transactions,
categorize expenses, and calculate their balance.
This method ensures faster debugging, better organization, and clear documentation—essential
skills for any professional developer.
Reference:
Downey, A. (2015). Think Python: How to Think Like a Computer Scientist. Green Tea Press.
[https://greenteapress.com/thinkpython2/thinkpython2.pdf](https://greenteapress.com/
thinkpython2/thinkpython2.pdf)