CBSE · 083Class XII · 2023Section B2 marks

Question 24(1)

30 March 2023 · Computer Science (083)

Write the output of the code given below :

python
def short_sub(lst, n):
    for i in range(0, n):
        if len(lst) > 4:
            lst[i] = lst[i] + lst[i]
        else:
            lst[i] = lst[i]

subject = ['CS', 'HINDI', 'PHYSICS', 'CHEMISTRY', 'MATHS']
short_sub(subject, 5)
print(subject)

Answer

text
['CSCS', 'HINDIHINDI', 'PHYSICSPHYSICS', 'CHEMISTRYCHEMISTRY', 'MATHSMATHS']

Explanation

The list has 5 elements, so len(lst) > 4 is always True. Each element at indices 0–4 is replaced with itself concatenated with itself.