Skip to content

Commit acfd97d

Browse files
rishikeshs soln2 for 2_arrays_exercise.md
1 parent 7d353b8 commit acfd97d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

data_structures/2_Arrays/2_arrays_exercise.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@
88
5. May - 2190
99

1010
Create a list to store these monthly expenses and using that find out,
11+
#solution
12+
expenses=[2200,2350,2600,2130,2190]
13+
print("in feb,how many dollars spent extra compared to jan",expenses[1]-expenses[0])
14+
print("total expenses in first quarter of year",expenses[0]+expenses[1]+expenses[2])
15+
print("did i spend exactly 2000 in any month?")
16+
for i in expenses:
17+
if i==2000:
18+
return true
19+
break
20+
else:
21+
return false
22+
expenses.append(1980)
23+
expenses[3]=expenses[3]-200
24+
print("got refund in april",expenses[3])
25+
26+
27+
28+
29+
1130

1231
1. In Feb, how many dollars you spent extra compare to January?
1332
2. Find out your total expense in first quarter (first three months) of the year.
@@ -23,6 +42,12 @@ Create a list to store these monthly expenses and using that find out,
2342
```
2443
heros=['spider man','thor','hulk','iron man','captain america']
2544
```
45+
print(len(heros))
46+
heros.append('black panther')
47+
heros.pop(6)
48+
heros.insert(3,'black panther')
49+
heros[1:3]='doctor strange'
50+
heros.sort()
2651

2752
Using this find out,
2853

@@ -41,5 +66,15 @@ Using this find out,
4166
3. Create a list of all odd numbers between 1 and a max number.
4267
Max number is something you need to take from a user using input() function
4368

69+
int max_num=print("enter your max odd num ",int(input())
70+
oddnos=[]
71+
for i in range(1,max_num)
72+
if(i%2==0)
73+
oddnos.append(i)
74+
75+
76+
77+
78+
4479
[Solution](https://github.com/codebasics/data-structures-algorithms-python/blob/master/data_structures/2_Arrays/Solution/3_odd_even_numbers.py)
4580

0 commit comments

Comments
 (0)