I was trying to do an exercise ,which asked us to solve this following problem Exercise problem image which I tried to do ,but by not using same exact keywords as shown in the exercise.
Here is my code
def StringLength(length_of_String):
return len(text)
text = input("length_of_String :")
if type(text) == int:
print ("python doesn't show length of integers")
else :
print (len(text))
But the problem I get here is , if I add any text say like"joker" . It will output me length as "5",which is correct .
But when I type any integer or float , say "101" , it still prints it length as "3" because it is reading it as a string.
So how come I add Variable in which when I input a integer or string , it should recognise it as a string or an integer
Aucun commentaire:
Enregistrer un commentaire