Ejercicio
Punto Flotante, Unidades De Velocidad
Objectivo
Desarrollar un programa Python para solicitar al usuario una distancia (en metros) y el tiempo empleado (como tres números: horas, minutos, segundos), y mostrar la velocidad en metros por segundo, kilómetros por hora y millas por hora (pista: 1 milla = 1609 metros).
Ejemplo de ejercicio de Python
Mostrar código Python
# Prompt the user for the distance in meters
distance = float(input("Enter the distance in meters: "))
# Prompt the user for the time taken (hours, minutes, seconds)
hours = int(input("Enter the time in hours: "))
minutes = int(input("Enter the time in minutes: "))
seconds = int(input("Enter the time in seconds: "))
# Convert the total time to seconds
total_time_in_seconds = hours * 3600 + minutes * 60 + seconds
# Calculate the speed in meters per second
speed_mps = distance / total_time_in_seconds
# Calculate the speed in kilometers per hour
speed_kph = (distance / 1000) / (total_time_in_seconds / 3600)
# Calculate the speed in miles per hour (1 mile = 1609 meters)
speed_mph = (distance / 1609) / (total_time_in_seconds / 3600)
# Display the results
print(f"Speed: {speed_mps:.2f} meters per second")
print(f"Speed: {speed_kph:.2f} kilometers per hour")
print(f"Speed: {speed_mph:.2f} miles per hour")
Output
Case 1:
Enter the distance in meters: 5000
Enter the time in hours: 1
Enter the time in minutes: 30
Enter the time in seconds: 0
Speed: 2.78 meters per second
Speed: 10.00 kilometers per hour
Speed: 6.21 miles per hour
Case 2:
Enter the distance in meters: 10000
Enter the time in hours: 2
Enter the time in minutes: 0
Enter the time in seconds: 0
Speed: 1.39 meters per second
Speed: 5.00 kilometers per hour
Speed: 3.11 miles per hour
Código de ejemplo copiado
Comparte este ejercicio de Python