-
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
Open
Danielef12
wants to merge
2
commits into
tomorrowdevs-projects:main
Choose a base branch
from
Danielef12:solution/final-project
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
''' Expensive Tracking App: A simple tool to track and organize your travel expenses on a daily basis''' | ||
|
||
|
||
print("=" * 60) | ||
print(" Travel Expense Tracking App") | ||
print("=" * 60) | ||
|
||
travel_day = int(input("\nDays on the road: ")) | ||
budget_amount = float(input("Total budget for the trip: ")) | ||
categories = ["lodging", "transportation" , "meals" , "other" ] | ||
expense = [] | ||
|
||
print("Keep track of your expens: ") | ||
|
||
# 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} ---") | ||
expense_day = {} # dictionary to which {"day 1": {"category": expense}} will be added | ||
for category in categories: # For each category in the category list | ||
|
||
while True: | ||
try: | ||
amount = float(input(f"Insert the amount for {category}: ")) # Insert the amount of the category | ||
expense_day[category] = amount # day[category] = add expense value | ||
break | ||
except ValueError: # If I type something other than a number | ||
print("Ivalid value, please check.") | ||
expense.append(expense_day) # the dictionary with {"category" : expense} will be added to the expense list. Each dictionary is equivalent to one day | ||
|
||
|
||
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 commentThe 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? |
||
total_day = 0 | ||
for expence in day.values(): | ||
total_day += expence | ||
total += expence | ||
print(f"Day {i}: {day}.") | ||
print(f"Today you have spent: {total_day}€.\n") | ||
|
||
|
||
modify_expenses = input("You want to change some expenses? (y/n): ") | ||
|
||
while modify_expenses.lower() == "y": | ||
day = int(input("Insert the day to modify (es. 1, 2, 3...): ")) - 1 | ||
category = input("Enter the category to edit: ").lower() | ||
|
||
if day >= 0 and day < len(expense) and category in expense[day]: | ||
new_expense = float(input(f"Enter the new expense for {category} of the day {day + 1}: ")) | ||
expense[day][category] = new_expense | ||
print("Modify correctly.") | ||
|
||
total = 0 | ||
for i, day in enumerate(expense, 1): | ||
total_day = 0 | ||
for expenses in day.values(): | ||
total_day += expenses | ||
total += expenses | ||
print(f"Day {i}: {day}.") | ||
print(f"Today you have spent: {total_day}€.\n") | ||
|
||
else: | ||
print("Day or category wrong, try again") | ||
modify_expenses = input("Do you want to change other values? (y/n): ") | ||
|
||
|
||
|
||
# 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 commentThe reason will be displayed to describe this comment to others. Learn more. use the
|
||
total_general = 0 | ||
|
||
for day in expense: | ||
for category in categories: | ||
total_categories[category] += day[category] | ||
|
||
print("\n--- TOTAL EXPENSE CATEGORIES ---") | ||
for category, total in total_categories.items(): | ||
print(f"- {category}: {total}€") | ||
|
||
|
||
print(f"\nYou spent a total of: {total:.2f}€") | ||
|
||
remainder = budget_amount - total | ||
if remainder > 0: | ||
print(f"Available budget: {remainder:.2f}€\n") | ||
elif remainder == 0: | ||
print("You've used up your entire budget for this trip\n") | ||
else: | ||
print(f"You went over budget for {abs(remainder):.2f}€\n") | ||
|
||
|
||
print("*" * 60) | ||
print(" Thanks for using this Travel Expense Tracking App") | ||
print("*" * 60) |
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.
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: