Skip to the content.

3.10 Hacks

Popcorn and Homework hacks for 3.10

#POPCORN HACK 1
aList = ['black', 'white', 'brown', 'yellow']
aList.append('purple')
print(aList)
['black', 'white', 'brown', 'yellow', 'purple']
#POPCORN HACK 2 INSERT
aList = ['black', 'white', 'brown', 'yellow']
aList.insert(0, 'purple')
print(aList)
['purple', 'black', 'white', 'brown', 'yellow']
#POPCORN HACK 2 REMOVE
aList = ['purple', 'black', 'white', 'brown', 'yellow']
aList.remove('yellow')
print(aList)
['purple', 'black', 'white', 'brown']
#POPCORN HACK 2 DELETE
aList = ['purple', 'black', 'white', 'brown', 'yellow']
del aList[3]
print(aList)
['purple', 'black', 'white', 'yellow']
#POPCORN HACK 3
aList = ['purple', 'black', 'white', 'brown', 'yellow']
aList[1] = 'pink'
print(aList)
['purple', 'pink', 'white', 'brown', 'yellow']
#HOMEWORK HACK

nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

even_sum = 0
for score in nums:
    if score % 2 == 0:  
        even_sum += score  

print("Sum of even numbers in the list:", even_sum)

min_value = nums[0]  
max_value = nums[0]  

for score in nums:
    if score < min_value:  
        min_value = score
    if score > max_value:  
        max_value = score

print("Minimum value in the list:", min_value)
print("Maximum value in the list:", max_value)

Sum of even numbers in the list: 30
Minimum value in the list: 1
Maximum value in the list: 10