I've just started learning python.
I came across this excercise: Ask a user to input a value, if it's a string count it's length, if it's an int or a float, return a sentece, and ask them to input a string instead if ints and floats.
I came up with this:
def string_length(mystring):
return len(mystring)
mystring = input("Enter your string to count: ")
if type(mystring) == int:
print("You must input a string, integers don't have length!")
elif type(mystring) == float:
print("You must input a string, floats don't have length!")
else:
print(string_length(mystring))
the problem is that it counts the characters of ints and floats as well like this:
Enter your string to count: 111
3
Process finished with exit code 0
i'm using pycharm and the prebuilt "command line" i'm not executing the program by running it normally.