PYTHON SOLUTION OF WEEK 5 ASSIGNMENT
1. len([1, 2, 3]) == len(['a', 'b', 'c']) , len('mom') in [1, 2, 3]
2. secret('123')
3. Return a list containing every third item from L starting at index 0.
4. i = i + 2
6.
def for_version(L):
found_even = False
total = 0
for num in L:
if num % 2 != 0 and not found_even:
total = total + num
else:
found_even = True
return total
7. letters.sort() and numbers.reverse() (in case of numbers question)
8. ['carrot', 'celery', 'broccoli', 'potato', 'asparagus']
9.
while playlist.count(song) > 3:
playlist.pop(playlist.index(song))
while playlist.count(song) > 3:
playlist.remove(song)
10. a = [1, 'A', 3] , b[-2] = 'A' , a[1] = 'A' , b[1] = 'AB'
b = [1, 'A', 3] a[1] = a[1][0]
11. a = [1, 'A', 3]
b = [1, 'A', 3]
12. None
[3, 4, 5]
13.
values = []
for num in range(1, 4):
values.append(num * 3)
print(values)
values = []
for num in range(3, 10, 3):
values.append(num)
print(values)
14. range(3, 23, 8) , range(3, 20, 8)
No comments:
Post a Comment