Simple attempt to transform into float (with this you can know if the string typed has the same format as a float):
h = input("Informe sua altura: ")
try:
float(h)
print('É float, altura: ' ,h)
except ValueError as err:
print('Não é float')
Repetition of input
, no function:
while True:
h = input("Informe sua altura: ")
try:
float(h)
break
except ValueError as err:
print('formato errado')
print('altura:', h)
Repetition of input
, with recursive function:
def return_float():
h = input("Informe sua altura: ")
try:
return float(h)
except ValueError as err:
print('Formato errado, por favor tente outravez')
return return_float()
print('a sua altura é', return_float())
At last to follow your logic and for what you asked me in the comment, "... I can not use neither try nor except ...", you can do this:
while True:
h = input("Informe sua altura: ")
if h.replace('.', '', 1).isdigit():
break
print('formato errado')
print('altura:', float(h))