I am using conditional statement in a function to ask weather an input is float/string/integer and display certain output if it determine each of the input but the input are all taken as string, how to tell the program to identify each input as string/float/integer?
this is the code below;
def strl(name):
lname = len(name)
return lname
name = input('please enter your name: ')
if type(name) == int:
print("sorry, integars don't have a length")
elif type(name) == float:
print('sorry, float do not have length ')
else:
print(strl(name))
print(type(name))
>Solution :
def strl(name):
lname = len(name)
return lname
name = input('please enter your name: ')
try:
int(name)
print("sorry, integars don't have a length")
except:
try:
float(name)
print('sorry, float do not have length ')
except:
print(strl(name))
print(type(name))