Complete the code to define a function that prints the length of any input.
def print_length([1]): print(len(item)) print_length("hello")
The function parameter should be named item because the print statement uses item to get the length.
Complete the code to call the function with a list argument.
def print_length(item): print(len(item)) print_length([1])
The function expects an object with length. A list like [1, 2, 3] works well.
Fix the error in the function to handle any input and print its length.
def print_length(item): print([1](item)) print_length(12345)
length or size causes NameError.The built-in function len() returns the length of an object. Using len(item) is correct.
Fill both blanks to create a function that works with strings and lists, printing their lengths.
def print_length([1]): print(len([2])) print_length("test") print_length([1, 2, 3])
The parameter and the variable inside len() must be the same. Here, both are data.
Fill all three blanks to create a function that prints the length of the uppercase version of a string argument.
def print_upper_length([1]): upper_str = [2].upper() print(len([3])) print_upper_length("hello")
text.upper() directly in print causes error because it's not stored.The parameter is text. We call text.upper() and store it in upper_str. Then print length of upper_str.