Skip to content

Commit 6a54a60

Browse files
Add files via upload
1 parent 947df54 commit 6a54a60

7 files changed

+63
-57
lines changed

Section_04/Assignment_09.py

+26-18
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,15 @@
3636
}
3737

3838

39-
# Your Code below:
39+
# Your Code Below:
4040
# --------------------------------------
41-
line_list = []
42-
for line in fr:
43-
columns = line.split("|")
44-
lookup_val = columns[0]
45-
# if lookup_val not in d.keys():
4641

47-
if(d.get(lookup_val) is None): # Can't find email in dict
4842

49-
next_number = int(max(d.values())) + 1
50-
d[lookup_val] = str(next_number)
51-
columns[0] = str(next_number)
52-
line_list.append("|".join(columns))
5343

54-
else: # we were able to find email in dictionary
55-
columns[0] = d.get(lookup_val)
56-
line_list.append("|".join(columns))
5744

5845

59-
fr = line_list
6046

61-
62-
63-
# don't change the below:
47+
# don't change the lines below:
6448
# --------------------------------------
6549
print("Value of fr: ")
6650
print(fr)
@@ -82,6 +66,30 @@
8266

8367

8468

69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
8593
# Solution:
8694
#
8795
# line_list = []

Section_04/assignment_01.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@
1212
1313
"""
1414

15-
def twelver(a, b):
16-
return (a == 12 or b == 12 or a+b == 12)
15+
# Your Code Below:
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
1726

1827

1928

Section_04/assignment_02.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@
1717
pay_extra(True, 6) -> true
1818
"""
1919

20-
def pay_extra(working, hour):
21-
return (working and (hour < 8 or hour > 20))
20+
# Your Code Below:
21+
22+
23+
24+
25+
26+
27+
28+
2229

2330

2431

Section_04/assignment_03.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
sequence([]) → False
1212
"""
1313

14-
def sequence(num_list):
15-
for i in range(len(num_list)-2):
16-
if num_list[i] == 1 and num_list[i+1] == 2 and num_list[i+2] == 3:
17-
return True
14+
# Your Code Below:
15+
16+
17+
18+
1819

19-
return False
2020

21-
print(sequence([]))
2221

2322

2423

Section_04/assignment_04.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@
99
1010
"""
1111

12-
def grow_string(str):
12+
# Your Code Below:
13+
14+
15+
1316

14-
result = ""
1517

16-
for i in range(len(str)):
17-
result = result + str[:i + 1]
1818

19-
return result
2019

21-
print(grow_string("Imtiaz"))
2220

2321

2422

Section_04/assignment_05.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,12 @@
1313
1414
"""
1515

16-
def first3(numbers):
16+
# Your Code Below:
17+
1718

18-
end = len(numbers)
1919

20-
if end > 4:
21-
end = 4
2220

23-
for i in range(end): # loop over index 0,1,2,3
24-
if numbers[i] == 6:
25-
return True
2621

27-
# if we get here, the loop is over and we didn't find a 6
28-
return False
2922

3023

3124
print(first3([1,2,6,3,0,0])) # true

Section_04/assignment_06.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,8 @@
1616
1717
"""
1818

19-
def last2(str):
19+
# Your Code Below:
2020

21-
if len(str) <= 2:
22-
return 0
23-
24-
# last 2 chars can also be extracted with str[-2:]
25-
last2 = str[len(str) - 2:]
26-
count = 0
27-
28-
for i in range(len(str) - 2):
29-
sub = str[i : i+2]
30-
if sub == last2:
31-
count = count + 1
32-
33-
return count
3421

3522

3623
print(last2('hixxhi')) #→ 1
@@ -53,6 +40,11 @@ def last2(str):
5340

5441

5542

43+
44+
45+
46+
47+
5648

5749

5850

0 commit comments

Comments
 (0)