15. Python Lists - For Loop - Quiz

1. What is the output of the following code?

basket = ["Guava", "banana", "cherry"]
for x in basket:
   print(x)
Answer: Guava banana cherry (on separate lines)
2. Which of the following is the correct syntax to iterate through a list named grades?
Answer: for variable in grades:
3. What is the output of this code?

x = ['ab', 'cd']
for i in x:
   i.upper()
print(x)
Answer: ['ab', 'cd']
4. What will be the output of the following code?

numbers = [1, 2, 3, 4]
for n in numbers:
   print(n * 2)
Answer: 2 4 6 8
5. What will be the output of the following code?

nums = [1, 2, 3, 4]
total = 0
for n in nums:
   if n % 2 == 0:
       total = total + n
Print(total)
Answer: 6
Score: 0 / 0 answered