हिंदी

Write the output of the code given below: def short_sub (1st, n): for i in range (0, n): if len (1st) > 4: lst [i] = lst [i] + lst [i] else: lst [i] = lst [i] subject - Computer Science (Python)

Advertisements
Advertisements

प्रश्न

Write the output of the code given below:

def short_sub (1st, n):
for i in range (0, n):
      if len (1st) > 4:
          lst [i] = lst [i] + lst [i]
      else:
          lst [i] = lst [i]
subject = ['CS', 'HINDI', 'PHYSICS', 'CHEMISTRY', 'MATHS'] 
short_sub (subject, 5)
print (subject)
लघु उत्तरीय
Advertisements

उत्तर

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

Explanation:

If the number of elements in the list is greater than four, the code iterates through the list's elements and changes the list with element + element. Because the list has five elements, each element is duplicated twice in all slots.

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2022-2023 (March) Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×