Computer Science
Write a program as per following specification :
"'Return the length of the shortest string in the tuple of strings str_tuple.
Precondition: the tuple will contain at least one element."'
Python
Python Tuples
10 Likes
Answer
str_tuple = ("computer science with python" ,"Hello Python" ,"Hello World" ,"Tuples")
shortest_str = min(str_tuple)
shortest_str_len = len(shortest_str)
print("The length of shortest string in the tuple is:", shortest_str_len)
Output
The length of shortest string in the tuple is: 12
Answered By
6 Likes
Related Questions
Write a program that interactively creates a nested tuple to store the marks in three subjects for five students and also add a function that computes total marks and average marks obtained by each student.
Tuple will look somewhat like :
marks( (45, 45, 40), (35, 40, 38),(36, 30, 38), (25, 27, 20), (10, 15, 20) )Write a program that inputs two tuples and creates a third, that contains all elements of the first followed by all elements of the second.
Create a tuple containing the squares of the integers 1 through 50 using a for loop.
Create a tuple ('a', 'bb', 'ccc', 'dddd', … ) that ends with 26 copies of the letter z using a for loop.