Computer Science, asked by alwinsajan225, 9 days ago

See the following program snippet which lists out the names of all students:
student_list = ["Ravi", "Sunita", "Gopal", "Salma", "Lily"]
number_of_students = len(student_list)
i = 0
while i <= number_of_students:
print(student_list[i])
i += 1
When it was run, it gave the following error on the last line
IndexError: list index out of range
Which of these will correct the error?
a. Replacing i = 0 with i = 1
b. Replacing i <= number_of_students with i < number_of_students
c. Replacing student_list[i] with student_list[i-1]
d. Replacing i += 1 with i = i + 1

is the answer is C or B

Answers

Answered by kakalisarkarraju2011
0

Explanation:

See the following program snippet which lists out the names of all students:

student_list = ["Ravi", "Sunita", "Gopal", "Salma", "Lily"]

number_of_students = len(student_list)

i = 0

while i <= number_of_students:

print(student_list[i])

i += 1

When it was run, it gave the following error on the last line

IndexError: list index out of range

Which of these will correct the error?

a. Replacing i = 0 with i = 1

b. Replacing i <= number_of_students with i < number_of_students

c. Replacing student_list[i] with student_list[i-1]

d. Replacing i += 1 with i = i + 1

is the answer is C or B

Similar questions