Write a for loop
that sums up integers in the list below, and skips None
values.
sequence = [None, 2, 3, 6, None, 8, None, 11]
sequence = [None, 12, 832, 2, None, 2, None, 11]
total = 0
for i in range(0,len(sequence)):
if type(sequence[i]) == int:
total += sequence[i]
total
859
Write a while-loop
that prints a number as long as it is an even number less than 10, but otherwise, prints it is not less than 10. For example, your output should look like this:
0 is even and less than 10
2 is even and less than 10
.
.
.
10 is not less than 10
number = 0
while number <= 10:
if number % 2 == 0 and number < 10:
print(f"{number} is even and less than 10")
else:
print(f"{number} is not less than 10")
number += 2
0 is even and less than 10
2 is even and less than 10
4 is even and less than 10
6 is even and less than 10
8 is even and less than 10
10 is not less than 10