366,944 views
33 votes
33 votes
What type of error occurs in this program?

listA = [10, 3, 11, 4, 1]
num1 = listA[2]
num2 = listA[8]
sum = num1 + num2
print(sum)

A. Logic Error
B. Runtime Error
C. List Error
D. Syntax Error

User RPichioli
by
3.0k points

2 Answers

26 votes
26 votes

Answer:

Explanation: C. Runtime Error

By looking at the code snippet, the error occurs on line 3:

num2 = listA[8]

The reason for this is because listA only has 5 elements in it. In order to be able to access listA[8], listA would have to have at least 9 elements inside of it, which it does not.

In Python, this would raise an IndexError which is a type of Runtime Error.

User Tmcallaghan
by
3.0k points
7 votes
7 votes

Answer: B. Runtime Error

Step-by-step explanation:

I think you are wrong on this num2 = listA[8]! It would cause Runtime Error that why I pick B!

User Erwin Brandstetter
by
3.3k points