def num(s):
if not s:
return ""
try:
list_s = s.split(".")
# If there is no fractional part or fractional part is 0 return int(s) else float(s)
if ( len(list_s) == 1 ) or ( int(list_s[1]) == 0 ):
return int(s)
else:
return float(s)
except:
return 0
str1 = ""
str2 = "0.0"
str3 = "1.1"
str4 = "10"
print("str1 = "+str(num(str1)))
print("str2 = "+str(num(str2)))
print("str3 = "+str(num(str3)))
print("str4 = "+str(num(str4)))