|
1 |
| -# 1. Let us say your expense for every month are listed below, |
2 |
| -# 1. January - 2200 |
3 |
| -# 2. February - 2350 |
4 |
| -# 3. March - 2600 |
5 |
| -# 4. April - 2130 |
6 |
| -# 5. May - 2190 |
7 |
| -# |
8 |
| -# Create a list to store these monthly expenses and using that find out, |
9 |
| -# |
10 |
| -# 1. In Feb, how many dollars you spent extra compare to January? |
11 |
| -# 2. Find out your total expense in first quarter (first three months) of the year. |
12 |
| -# 3. Find out if you spent exactly 2000 dollars in any month |
13 |
| -# 4. June month just finished and your expense is 1980 dollar. Add this item to our monthly expense list |
14 |
| -# 5. You returned an item that you bought in a month of April and |
15 |
| -# got a refund of 200$. Make a correction to your monthly expense list |
16 |
| -# based on this |
| 1 | +arr = [2200,2350,2600,2130,2190] |
17 | 2 |
|
18 |
| -exp = [2200,2350,2600,2130,2190] |
| 3 | +# January - 2200 |
| 4 | +# February - 2350 |
| 5 | +# March - 2600 |
| 6 | +# April - 2130 |
| 7 | +# May - 2190 |
19 | 8 |
|
20 | 9 | # 1. In Feb, how many dollars you spent extra compare to January?
|
21 |
| -print("In feb this much extra was spent compared to jan:",exp[1]-exp[0]) # 150 |
| 10 | +print(arr[1]-arr[0]) |
22 | 11 |
|
23 |
| -# 2. Find out your total expense in first quarter (first three months) of the year |
24 |
| -print("Expense for first quarter:",exp[0]+exp[1]+exp[2]) # 7150 |
| 12 | +# 2. Find out your total expense in first quarter (first three months) of the year. |
| 13 | +print(arr[0]+arr[1]+arr[2]) |
25 | 14 |
|
26 | 15 | # 3. Find out if you spent exactly 2000 dollars in any month
|
27 |
| -print("Did I spent 2000$ in any month? ", 2000 in exp) # False |
| 16 | + |
| 17 | +print(2000 in arr) |
| 18 | + |
28 | 19 |
|
29 | 20 | # 4. June month just finished and your expense is 1980 dollar. Add this item to our monthly expense list
|
30 |
| -exp.append(1980) |
31 |
| -print("Expenses at the end of June:",exp) # [2200, 2350, 2600, 2130, 2190, 1980] |
| 21 | + |
| 22 | +arr.append(1980) |
| 23 | +print(arr) |
32 | 24 |
|
33 | 25 | # 5. You returned an item that you bought in a month of April and
|
34 | 26 | # got a refund of 200$. Make a correction to your monthly expense list
|
35 | 27 | # based on this
|
36 |
| -exp[3] = exp[3] - 200 |
37 |
| -print("Expenses after 200$ return in April:",exp) # [2200, 2350, 2600, 1930, 2190, 1980] |
| 28 | + |
| 29 | +arr[3] = arr[3] - 200 |
| 30 | +print(arr) |
0 commit comments