-
Notifications
You must be signed in to change notification settings - Fork 2
Solution for final project #198
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: main
Are you sure you want to change the base?
Solution for final project #198
Conversation
|
||
# 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.
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): |
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.
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 |
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.
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]
My solution for final project