I'm a new to Python and a piece of code doesn't seem to work as desired. Here is the code:
#Create a function that takes any string as argument and returns the length of that string. Provided it can't take integers.
def length_function(string):
length = len(string)
return length
string_input=input("Enter the string: ")
if type(string_input) == int:
print("Input can not be an integer")
else:
print(length_function(string_input))
Whenever I type an integer in the result, it gives me the the number of digits in that integer. However, I want to display a message that "Input can not be an integer".
Is there any error in my code or is there another way of doing this. Please respond. Thank You!
length_functionis a bit redundant when you can calllendirectly. Also if you insist you can just dolength_function = len