Our Office
Ernakulam, Kottayam
Email Us
linusfacts@gmail.com
Call Us
+91 9544409513
1. Given two lists, list1 = [1, 2, 3, 4, 5] and list2 = [4, 5, 6, 7, 8]<br>2. Use a for loop to find the common elements between the two lists and store them in a new list. 1. Given a string, word = "algorithm"<br>2. Use a for loop to count the number of vowels and consonants in the word.<br>3. Print the counts at the end. 1. Use a for loop with the range function to print numbers from 0 to 9.<br>2. Modify the loop to calculate and print their sum. 1. Given the list colors = ["red", "green", "blue", "yellow"]<br>2. Use a for loop to print each color. 1. Use a for loop to print the multiplication table for the number 5 (from 5x1 to 5x10). 1. Display the number from -10 to 0 using a for loop.<br>2. Modify this for loop to only get 0 -2 -4 -6 -8 and -10 1. Given a list, fruits = ["apple", "banana", "cherry"]<br>2. Use a for loop to create a new list that duplicates the items in the fruits list. The result should be ["apple", "apple", "banana", "banana", "cherry", "cherry"] 1. Given a string, sentence = "Hello, world!".<br>2. Use a for loop to count how many times the letter 'l' appears in the string. 1. Use a for loop to print all even numbers from 2 to 20.

QUESTIONS

1. Given two lists, list1 = [1, 2, 3, 4, 5] and list2 = [4, 5, 6, 7, 8]
2. Use a for loop to find the common elements between the two lists and store them in a 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}")

1. Given a string, word = "algorithm"
2. Use a for loop to count the number of vowels and consonants in the word.
3. Print the counts at the end.

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}')

1. Use a for loop with the range function to print numbers from 0 to 9.
2. Modify the loop to calculate and print their sum.

Right Answer:


sum=0
for i in range(1,9):
print(i)
sum+=i
print(f'sum:{sum}')

1. Given the list colors = ["red", "green", "blue", "yellow"]
2. Use a for loop to print each color.

Right Answer:


colours = ["red", "green", "blue", "yellow"]
for i in colours:
print(I)

1. Use a for loop to print the multiplication table for the number 5 (from 5x1 to 5x10).

Right Answer:


for i in range(1, 10):
mult = i * 5
print(f'{i} * 5 = {mult}')

1. Display the number from -10 to 0 using a for loop.
2. Modify this for loop to only get 0 -2 -4 -6 -8 and -10

Right Answer:


for i in range(-10,1):
print(i)

#2
for i in range(0,-11,-2):
print(i)

1. Given a list, fruits = ["apple", "banana", "cherry"]
2. Use a for loop to create a new list that duplicates the items in the fruits list. The result should be ["apple", "apple", "banana", "banana", "cherry", "cherry"]

Right Answer:


fruits = ["apple", "banana", "cherry"]
new_list=[]
for i in fruits:
new_list.append(i)
new_list.append(i)
print(new_list)

1. Given a string, sentence = "Hello, world!".
2. Use a for loop to count how many times the letter 'l' appears in the string.

Right Answer:

sentence = "Hello, world!"
count=0
for i in sentence:
if i == "l":
count+=1
print(count)

1. Use a for loop to print all even numbers from 2 to 20.

Right Answer:


for i in range(2,20,2):
print(i)
#or
for i in range(2,20):
if i%2==0:
print(i)

Get In Touch

Kochi, Pala,Ernakulam

+91 9544409513

linuslearning.in@gmail.com

Our Courses
Newsletter

Those people who develop the ability to continuously acquire new and better forms of knowledge that they can apply to their work and to their lives will be the movers and shakers in our society for the indefinite future