Solution for final project - #198
Open
Danielef12 wants to merge 2 commits into
Open
Conversation
effedib
reviewed
May 26, 2025
|
|
||
| # User add manually all expense for every category in every day | ||
| for day in range(1,travel_day + 1): # for every day on travel days | ||
| print(f"--- Expense for day {day} ---") |
There was a problem hiding this comment.
simpler and more intuitive for a developer, used to starting from 0 when talking about indexes:
for day in range(travel_day):
print(f"--- Expense for day {day+1} ---")
effedib
reviewed
May 26, 2025
|
|
||
| print("total expense") # Calculate total daily spending by adding all categories | ||
| total = 0 | ||
| for i, day in enumerate(expense, 1): |
There was a problem hiding this comment.
why not sum every expense while the user is entering the input and avoid others loop?
effedib
reviewed
May 26, 2025
|
|
||
|
|
||
| # sum of every expenses of all category | ||
| total_categories = {category: 0 for category in categories} # I create a dictionary where each key is a category and each value is the total expenses of that category |
There was a problem hiding this comment.
use the setdefault dict method to avoid useless loops:
for day in expense:
for category in categories:
total_categories[category] = total_categories.setdefault(category, 0) + day[category]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
My solution for final project