17.1k views
5 votes
What is printed by executing the code?

myList = []
for index in range(15):
myList.append("Hi")
print(len(myList))
a) 15
b) 14
c) 1
d) 0

User Siegfred
by
8.4k points

1 Answer

7 votes

Final answer:

The code will print the number 15, which is the length of the list 'myList' after appending the string "Hi" 15 times within a for loop.

Step-by-step explanation:

The student is asking what is printed after executing a snippet of Python code. In the given code, myList is initialized as an empty list. The for loop uses range(15) to iterate 15 times, and in each iteration, myList.append("Hi") is called, adding the string "Hi" to the list. Since the range starts at 0 and ends at 14 (which is a total of 15 iterations), "Hi" is appended to the list 15 times. After the loop finishes, print(len(myList)) will output the length of myList, which is 15 in this case.

User Anton Sizikov
by
8.1k points