Skip to content

Commit 2550a44

Browse files
committed
Arrays exercise from Youtube done
1 parent 7d353b8 commit 2550a44

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# TODO 1. Expense Exercise
2+
3+
expense_list = [("January", 2200), ("February", 2350), ("March",2600),
4+
("April", 2130), ("May", 2190)]
5+
6+
# Question 1.1
7+
question_1_1 = expense_list[1][1]-expense_list[0][1]
8+
print(f"Extra expense Feb vs Jan = {question_1_1}")
9+
10+
# Question 1.2
11+
total_expense_quarter_one = 0
12+
for month in range(0,3):
13+
total_expense_quarter_one += expense_list[month][1]
14+
15+
question_1_2 = total_expense_quarter_one
16+
print(f"Total expense for the first quarter = {question_1_2}")
17+
18+
# Question 1.3
19+
equals_2000 = False
20+
for month in range(0, len(expense_list)):
21+
if expense_list[month][1] == 2000:
22+
equals_2000 = True
23+
24+
if equals_2000:
25+
print(f"There is a monthly expense that is exactly 2000 dollars")
26+
else:
27+
print(f"There is no monthly expense that is exactly 2000 dollars")
28+
29+
# Question 1.4
30+
expense_list.append(("June", 1980))
31+
print(expense_list)
32+
33+
# Question 1.5
34+
expense_list[3] = ("April", expense_list[3][1] - 200)
35+
print(expense_list[3])
36+
37+
# TODO 2. Super Hero exercise
38+
39+
list_heroes = ["spider man", "thor", "hulk", "iron man", "captain america"]
40+
41+
# Question 2.1
42+
print("\n")
43+
print(len(list_heroes))
44+
45+
# Question 2.2
46+
list_heroes.append("black panther")
47+
print(list_heroes)
48+
49+
# Question 2.3
50+
list_heroes.remove("black panther")
51+
list_heroes.insert(2, "black panther")
52+
print(list_heroes)
53+
54+
# Question 2.4
55+
list_heroes[1], list_heroes[3] = "doctor strange", "doctor strange"
56+
print(list_heroes)
57+
58+
# Question 2.5
59+
list_heroes = sorted(list_heroes)
60+
print(list_heroes)
61+
62+
# TODO 3. Odd number exercise
63+
64+
user_odd_input = int(input("Input maximum number for the list of odd numbers. "))
65+
66+
list_of_odd_numbers = []
67+
68+
for i in range (1, user_odd_input+1):
69+
if i % 2 != 0:
70+
list_of_odd_numbers.append(i)
71+
72+
print(list_of_odd_numbers)
73+
74+
75+
76+

0 commit comments

Comments
 (0)