Skip to content

Commit dfa108c

Browse files
committed
make it cleaner
1 parent 6b8a495 commit dfa108c

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

data_structures/2_Arrays/my_arrays.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# 1. expenses
2+
print("\n##### 1. Expenses #####")
3+
expense = [2200, 2350, 2600, 2130, 2190]
4+
5+
print(f"1) In Feb, you spent extra \"{expense[1]-expense[0]}\" \
6+
compare to Jan.")
7+
8+
print(f"2) Total expense in first quarter is \
9+
\"{expense[0]+expense[1]+expense[2]}\".")
10+
11+
print(f"3) Is there any month you spent exactly $2000?\n\
12+
Ans: {any([x for x in expense if x == 2000])}")
13+
14+
expense.append(1980)
15+
print(f"4) Now expense of June is added, it is \"{expense[5]}\"")
16+
17+
print(f"5) The expense of April was {expense[3]}, but")
18+
expense[3] = expense[3]-200
19+
print(f" she returned one item, which costs $200, \
20+
so it is updated to \"{expense[3]}\".")
21+
22+
23+
# 2. marvel
24+
print("\n##### 2. Marvel #####")
25+
heros = ['spider man', 'thor', 'hulk', 'iron man', 'captain america']
26+
27+
print(f"1) Length of the list is \"{len(heros)}\".")
28+
29+
heros.append('black panther')
30+
print(f"2) Added black panther at the end of the list: {heros}")
31+
32+
heros.remove('black panther')
33+
heros.insert(3, 'black panther')
34+
print(f"3) After hulk, need black panther: {heros[:]}")
35+
36+
heros[1:3] = ['doctor stange']
37+
print(f"4) Removed thor and hulk and added doctor strage: {heros[:]}")
38+
39+
heros.sort()
40+
print(f"5) Sort the list: {heros}")
41+
42+
# 3. odd_numbers
43+
print("\n##### 3. Odd number list #####")
44+
45+
46+
def odd_between_1_and_max(max):
47+
return [i for i in range(1, max+1) if i % 2 == 1]
48+
49+
50+
m = int(input("Type max number for your list: "))
51+
list = odd_between_1_and_max(m)
52+
print(f"Your list is {list}")

0 commit comments

Comments
 (0)