CBSE Class 12 Computer Science Question 23 of 42

Solved 2024 Sample Question Paper CBSE Class 12 Computer Science (083) — Question 5

Back to all questions
5
Question

Question 21(b)

Write a function, lenWords(STRING), that takes a string as an argument and returns a tuple containing length of each word of a string. For example, if the string is "Come let us have some fun", the tuple will have (4, 3, 2, 4, 4, 3).

Answer
def lenWords(STRING):
    T = ()
    L = STRING.split()
    for word in L:
        length = len(word)
        T = T + (length, )
    return T