thing |
WhatAmI(thing) |
23 |
“integer” |
“23” |
“string with digits” |
“yabble” |
“string with letters” |
“yib4bie” |
“unidentified object” |
23.0 |
“unidentified object” |
“23.0” |
“unidentified object” |
def whatAmI(thing): if type(thing) == int: return "Integer" elif type(thing) == str: digits = 0 letters = 0 for ch in thing: if ch.isdigit(): digits += 1 elif ch.isalpha(): letters += 1 if digits == len(thing): return "String with digits" if letters == len(thing): return "String with letters" return "unidentified object" print(whatAmI(23)) print(whatAmI("23")) print(whatAmI("yabble")) print(whatAmI("yib4bie")) print(whatAmI(23.0)) print(whatAmI("23.0"))
Get Answers For Free
Most questions answered within 1 hours.