forked from codebasics/py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlists
40 lines (33 loc) · 993 Bytes
/
lists
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Lists
=====
Let us say your expense for every month are listed below,
January - 2200
February - 2350
March - 2600
April - 2130
May - 2190
Create a list to store these monthly expenses and using that find out,
In Feb, how many dollars you spent extra compare to January?
Find out your total expense in first quarter (first three months) of the year.
Find out if you spent exactly 2000 dollars in any month
June month just finished and your expense is 1980 dollar. Add this item to our monthly expense list
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.
Answer:
>>> exp = [2200,2350,2600,2130,2190]
# (a)
>>> exp[1]-exp[0]
150
# (b)
>>> exp[0]+exp[1]+exp[2]
7150
# (c)
>>> 2000 in exp
False # Means you didn’t spend 2000$ in any of the month
# (d)
>>> exp.append(1980)
>>> exp
[2200, 2350, 2600, 2130, 2190, 1980]
# (e)
>>> exp[3] = exp[3] - 200
>>> exp[3]
1930