Skip to content

Update transaction categorization logic and improve discount calculat…#7

Open
henryhabib wants to merge 1 commit into
masterfrom
hh-fix-logic-finance-5
Open

Update transaction categorization logic and improve discount calculat…#7
henryhabib wants to merge 1 commit into
masterfrom
hh-fix-logic-finance-5

Conversation

@henryhabib
Copy link
Copy Markdown
Owner

This pull request updates the transaction categorization logic and revises the discount calculation method in app.py to improve accuracy and clarity.

Transaction categorization:

  • Increased the threshold for categorizing a transaction as 'High Income' from 5,000 to 10,000 in categorize_transaction, making the classification stricter.

Discount calculation:

  • Changed the calculate_discount function to iteratively subtract 1% of the price for each percentage point in the discount rate, instead of using a direct multiplication, which may affect precision and behavior for fractional discount rates.…ion method

@henryhabib henryhabib requested a review from Copilot February 17, 2026 14:22
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates transaction categorization and discount calculation in app.py to modify thresholds and calculation methods.

Changes:

  • Increased the 'High Income' threshold from $5,000 to $10,000
  • Replaced direct discount calculation with an iterative subtraction approach

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Example 3/app.py
Comment on lines +62 to 66
discounted_price = price
for _ in range(int(discount_rate)):
discounted_price -= price * 0.01
return discounted_price

Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The discount calculation logic is incorrect. This implementation subtracts 1% of the original price repeatedly, which doesn't compound properly. For example, a 10% discount on $100 would give $90 (correct), but a 50% discount would give $50 (correct by coincidence), while a 100% discount would give $0 (correct), but the mathematical approach is fundamentally flawed for discounts that should compound. The original implementation price * (discount_rate / 100) was also incorrect as it calculated the discount amount rather than the final price. The correct implementation should be price * (1 - discount_rate / 100) to calculate the final discounted price.

Suggested change
discounted_price = price
for _ in range(int(discount_rate)):
discounted_price -= price * 0.01
return discounted_price
return price * (1 - discount_rate / 100.0)

Copilot uses AI. Check for mistakes.
Comment thread Example 3/app.py
"""
return price * (discount_rate / 100)
discounted_price = price
for _ in range(int(discount_rate)):
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting discount_rate to int truncates fractional percentages. A discount of 5.9% would be treated as 5%, losing precision and potentially causing financial inaccuracies.

Copilot uses AI. Check for mistakes.
Comment thread Example 3/app.py
Comment on lines +62 to +65
discounted_price = price
for _ in range(int(discount_rate)):
discounted_price -= price * 0.01
return discounted_price
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name 'discounted_price' is misleading since it starts as the full price and is progressively reduced. Consider renaming to 'final_price' or 'result' for clarity.

Suggested change
discounted_price = price
for _ in range(int(discount_rate)):
discounted_price -= price * 0.01
return discounted_price
final_price = price
for _ in range(int(discount_rate)):
final_price -= price * 0.01
return final_price

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants