Skip to content

Solution for final project - #198

Open
Danielef12 wants to merge 2 commits into
tomorrowdevs-projects:mainfrom
Danielef12:solution/final-project
Open

Solution for final project#198
Danielef12 wants to merge 2 commits into
tomorrowdevs-projects:mainfrom
Danielef12:solution/final-project

Conversation

@Danielef12

@Danielef12 Danielef12 commented May 26, 2025

Copy link
Copy Markdown

My solution for final project


# 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} ---")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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} ---") 


print("total expense") # Calculate total daily spending by adding all categories
total = 0
for i, day in enumerate(expense, 1):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why not sum every expense while the user is entering the input and avoid others loop?



# 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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]

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