- Notifications
You must be signed in to change notification settings - Fork1.6k
1_expenses#59
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
Harsamerveer wants to merge1 commit intocodebasics:masterChoose a base branch fromHarsamerveer:patch-1
base:master
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.
Uh oh!
There was an error while loading.Please reload this page.
Open
1_expenses#59
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
84 changes: 52 additions & 32 deletionsdata_structures/2_Arrays/Solution/1_expenses.py
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 |
---|---|---|
@@ -1,37 +1,57 @@ | ||
# 1. Let us say your expense for every month are listed below, | ||
# 1. January - 2200 | ||
# 2. February - 2350 | ||
# 3. March - 2600 | ||
# 4. April - 2130 | ||
# 5. May - 2190 | ||
def array_ex(arr, key, key1): | ||
# first question | ||
compare = int(arr[1][key]) - int(arr[0][key]) | ||
print("1. In Feb, how many dollars you spent extra compare to January? : ", compare) | ||
# second question | ||
first_quarter = int(arr[0][key]) + int(arr[1][key]) + int(arr[2][key]) | ||
print("2. Find out your total expense in first quarter (first three months) of the year. : ", first_quarter) | ||
# third question | ||
value = 0 | ||
for i in range(len(arr)): | ||
if arr[i][key] == "2130": | ||
value += 1 | ||
i += 1 | ||
if value == 1: | ||
print("3. Find out if you spent exactly 2130 dollars in any month : ", value, "time") | ||
elif value > 1: | ||
print("3. Find out if you spent exactly 2130 dollars in any month : ", value, "times") | ||
else: | ||
print("3. Find out if you spent exactly 2130 dollars in any month : Zero") | ||
# fifth question | ||
refund = 0 | ||
for i in range(len(arr)): | ||
if arr[i][key1] == "April": | ||
refund = int(arr[i][key]) - 200 | ||
i += 1 | ||
print("5. You returned an item that you bought in a month of April and got a refund of 200$. Make a correction to your monthly expense list based on this : ", refund) | ||
# fourth question | ||
item_expense = [{'Month': 'June', 'E_Amount': '1980'}] | ||
arr.append(item_expense) | ||
print("4. June month just finished and your expense is 1980 dollar. Add this item to our monthly expense list : ", | ||
arr) | ||
if __name__ == '__main__': | ||
expense = [ | ||
{'Month': 'January', 'E_Amount': '2200'}, | ||
{'Month': 'February', 'E_Amount': '2350'}, | ||
{'Month': 'March', 'E_Amount': '2600'}, | ||
{'Month': 'April', 'E_Amount': '2130'}, | ||
{'Month': 'May', 'E_Amount': '2190'} | ||
] | ||
array_ex(expense, key="E_Amount", key1="Month") | ||
exp[3] = exp[3] - 200 | ||
print("Expenses after 200$ return in April:",exp) # [2200, 2350, 2600, 1930, 2190, 1980] |
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.