my_list = ["apple", "banana", "cherry"]
for item in my_list:
print(item)
apple
banana
cherry
numbers = [1, 4, 2, 5, 7]
total = 0
for num in numbers:
total += num
print("The total is:", total)
The total is: 19
numbers = [12, 45, 3, 89, 21]
largest = 0
for num in numbers:
if num > largest:
largest = num
print("The largest number is", largest)
The largest number is 89
numbers = [1, 4, 2, 9, 7, 6]
even_count, odd_count = 0, 0
for num in numbers:
if num % 2 == 0:
even_count += 1
else:
odd_count += 1
print(f"Even number count: {even_count},
odd number count: {odd_count}")
Even number count: 3, odd number count: 3
numbers = [12, 45, 3, 89, 21]
largest = 0
for num in numbers:
if num > largest:
largest = num
print("The largest number is", largest)
Squares: [4, 16, 36, 64]
list1 = [1, 2, 3]
list2 = [4, 5, 6]
combined_list = []
for i in range(len(list1)):
combined_list.append(list1[i])
combined_list.append(list2[i])
print("Combined list:", combined_list)
Combined list: [1, 4, 2, 5, 3, 6]
list1 = ["cq", "ow", "de", "ig", "nr", "gt"]
text = ""
for i in range(len(list1)):
text += list1[i][0]
print(f"text is {text}")
text is coding
list1 = ["cp", "ou", "d ", "is", "ni", "g "]
text = ""
for i in range(0, len(list1)):
text += list1[i][0]
for i in reversed(range(0,len(list1))):
text += list1[i][1]
print(f"text is {text}")
text is coding is up
my_list = ["z", "e", "f", "e", "d", "o", "c"]
text = ""
for item in my_list[::-1]:
text += item
print(f"Text is {text}")
Text is codefez