GATE Assistant

Past questions › Data Science and Artificial Intelligence › GATE 2026

GATE 2026 · DA · NAT · 2 marks · Programming, Data Structures and Algorithms › Python Programming

GATE 2026 Data Science and Artificial Intelligence question: Consider the given Python program. code The output of the program is . (Answer in integer)

Consider the given Python program.

def fun(L, i=0):
    if i >= len(L)-1:
        return 0
    if L[i] > L[i+1]:
        L[i+1], L[i] = L[i], L[i+1]
        return 1+fun(L, i+1)
    else:
        return fun(L, i+1)
data = [5, 3, 4, 1, 2]
count = 0
for _ in range(len(data)):
    count += fun(data)
print(count)

The output of the program is __________ . (Answer in integer)

Show answer

Official answer: 8

Practise this question with exam-style marking

Discussion

No discussion yet.

Join the discussion