Q:

Semantic Error using Conditionals statements

I'm trying to build a code which executes the length of a string
This code should be able to accept only Strings and return their length but when integer or float values are given, it counts their length too.
def length(string):
    if type(string)== int:
        return "Not Available"
    elif type(string) == float:
        return "Not Allowed"
    else:
        return len(string)
string=input("Enter a string: ")
print(length(string))

Output: 
Enter a string: 45
2

A:

You expect to get output 'Not Available' for the input 45. But it won't happen because,
while reading input from keyboard default type is string. Hence, the input 45 is of type str. Therefore your code gives output 2.

