Question
If you have the following array, how many times will this loop run?
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
2
6
3
4
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
2
6
3
4
Answers
GPT-4o mini
The loop will run **3** times.
Here's the breakdown of the code:
- The array `fruits` contains three elements: "apple," "banana," and "cherry."
- The `for` loop iterates over each element in the `fruits` array one at a time.
- Therefore, the loop will run once for each fruit in the array.
So the correct answer is **3**.
Here's the breakdown of the code:
- The array `fruits` contains three elements: "apple," "banana," and "cherry."
- The `for` loop iterates over each element in the `fruits` array one at a time.
- Therefore, the loop will run once for each fruit in the array.
So the correct answer is **3**.