Computer Science, asked by priyanshudhiman807, 10 hours ago

WAP in Python to create a list of Strings and print the length of

individual elements(strings) of the list.​

Answers

Answered by Equestriadash
3

\tt l\ =\ list()\\while\ True:\\{\ \ \ \ \ }s\ =\ in put("Enter\ a\ string/Type\ 'S'\ to\ stop:\ ")\\{\ \ \ \ \ }if\ s\ ==\ 'S':\\{\ \ \ \ \ }{\ \ \ \ \ }break\\{\ \ \ \ \ }l.append(s)\\for\ i\ in\ l:\\{\ \ \ \ \ }print("The\ length\ of",\ "'"\ +\ i\ +\ "'",\ "is",\ str(len(i))\ +\ ".")

We initialize a list 'l' at the beginning for the strings to be stored into. We then start a loop to retrieve the input from the user, and we add a condition to end the loop in case the user wants to input a limited number of strings. Once the strings have been appended to the list, we start another loop to calculate the length of each element in the list using the len() function, which is used to calculate and return the number of characters, or rather, as per the question, the length of the element.

Similar questions