Sagot :
Réponse :
Bonjour,
Explications :
def isfloat(s):
try:
float(s)
return True
except ValueError:
return False
def ask_num(deb,fin,nature):
ok=False
while not ok:
nb=input("quel est votre nombre "+str(deb)+"< x < "+str(fin)+" :" )
if isfloat(nb):
x=float(nb)
if x >= deb and x <= fin:
if nature=="N":
if int(x)==x:
ok=True
x=int(x)
else:
ok=True
return x
#----------------------------------------------------
if __name__ == '__main__':
print ("nombre=",ask_num(2,5,"N") )
print ("nombre=",ask_num(2,5,"R") )