ЁЯУв Too many exams? DonтАЩt know which one suits you best? Book Your Free Expert ЁЯСЙ call Now!


    Question

    A function sum_matrix_elements(matrix, R, C) is designed

    to sum all elements of a matrix with R rows and C columns. The implementation uses nested loops: total_sum = 0 for i in range(R + 1): # Potential bug here ┬а ┬а for j in range(C + 1): # Potential bug here ┬а ┬а ┬а ┬а total_sum += matrix[i][j] Assuming R and C represent the actual number of rows and columns (e.g., R=3 for 3 rows), what kind of error will this code cause?
    A TypeError due to incorrect arithmetic. Correct Answer Incorrect Answer
    B KeyError because matrix elements are accessed by key. Correct Answer Incorrect Answer
    C IndexError because the loops attempt to access elements beyond the matrix boundaries. Correct Answer Incorrect Answer
    D ValueError because the sum might exceed integer limits. Correct Answer Incorrect Answer
    E SyntaxError due to incorrect loop syntax. Correct Answer Incorrect Answer

    Solution

    The correct answer is C

    Practice Next
    More IT Operating System Questions
    ask-question