-
Notifications
You must be signed in to change notification settings - Fork 26
Update transaction categorization logic and improve discount calculat… #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,7 +27,7 @@ def categorize_transaction(transaction_type, amount, description): | |||||||||||||||||
| Categorizes a transaction based on logic. | ||||||||||||||||||
| """ | ||||||||||||||||||
| if transaction_type == 'income': | ||||||||||||||||||
| if amount > 5000: | ||||||||||||||||||
| if amount > 10000: | ||||||||||||||||||
| return 'High Income' | ||||||||||||||||||
| elif 'bonus' in description.lower(): | ||||||||||||||||||
| return 'Bonus' | ||||||||||||||||||
|
|
@@ -59,7 +59,10 @@ def calculate_discount(price, discount_rate): | |||||||||||||||||
| """ | ||||||||||||||||||
| Calculates the discounted price. | ||||||||||||||||||
| """ | ||||||||||||||||||
| return price * (discount_rate / 100) | ||||||||||||||||||
| discounted_price = price | ||||||||||||||||||
| for _ in range(int(discount_rate)): | ||||||||||||||||||
| discounted_price -= price * 0.01 | ||||||||||||||||||
| return discounted_price | ||||||||||||||||||
|
Comment on lines
+62
to
+65
|
||||||||||||||||||
| 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
AI
Feb 17, 2026
There was a problem hiding this comment.
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.
| discounted_price = price | |
| for _ in range(int(discount_rate)): | |
| discounted_price -= price * 0.01 | |
| return discounted_price | |
| return price * (1 - discount_rate / 100.0) |
There was a problem hiding this comment.
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.