Previous exercises, we created this function:

>>> def string_length(mystring):
...    return len(mystring)

Calling the function with a string as the value for the argument mystring will return the length of that string.

If an integer is passed as an argument value:

string_length(10)

that would generate an error since the len() function doesn’t work for integers.

We have to modify the function so that when an integer is passed as input, the function should output a message like “Sorry integers don’t have length.”

So, How we do it?

>>> def string_length(mystring):
...    if type(mystring) == int:
...        return "Sorry, integers don't have length"
...    else:
...        return len(mystring)
...
>>> string_length(10)
"Sorry integers don't have length."

That’s it!