Respuesta :

tonb

Answer:

def calcSpeed(distance, time):

 return distance/time

def getStat(name, unit):

 while True:

   try:

     value = float(input("Enter the "+name+" in "+unit+": "))

     return value;

   except:

     print("You should enter a number, please try again.")

distance = getStat('distance', 'miles')

time = 0

while time == 0:

 time = getStat('time', 'hours')

 if (time == 0):

   print("Cannot divide by zero, so enter a non-zero time")

print("Your speed was {:.1f} mph".format(calcSpeed(distance, time)))

Explanation:

I hope you see what is happening in the code so you can give the second one a shot yourself!

BTW: I used different units, but for sure you'll be able to fix that!

Ver imagen tonb
ACCESS MORE