Right Answer:
for i in range(1, 10):
mult = i * 5
print(f'{i} * 5 = {mult}')
Right Answer:
for i in range(1, 10):
mult = i * 5
print(f'{i} * 5 = {mult}')
Right Answer:
for i in range(-10,1):
print(i)
#2
for i in range(0,-11,-2):
print(i)
Right Answer:
for i in range(2,20,2):
print(i)
#or
for i in range(2,20):
if i%2==0:
print(i)
Right Answer:
sum=0
for i in range(1,9):
print(i)
sum+=i
print(f'sum:{sum}')
Right Answer:
word = "algorithm"
vowel='aeiou'
vowel_count =0
consonant_count=0
for i in word:
if i in vowel:
vowel_count +=1
else:
consonant_count += 1
print(f'Vowels: {vowel_count}')
print(f'Consonants: {consonant_count}')
Right Answer:
fruits = ["apple", "banana", "cherry"]
new_list=[]
for i in fruits:
new_list.append(i)
new_list.append(i)
print(new_list)
Right Answer:
list1= [1, 2, 3, 4, 5]
list2 = [4, 5, 6, 7, 8]
common_elem=[]
for elem in list1:
if elem in list2:
common_elem.append(elem)
common_elem = set(common_elem) #keep unique elements
print(f"Common elements: {common_elem}")
Right Answer:
colours = ["red", "green", "blue", "yellow"]
for i in colours:
print(I)
Right Answer:
sentence = "Hello, world!"
count=0
for i in sentence:
if i == "l":
count+=1
print(count)