Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.4 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69162d64f96574d9bb629efe Challenge 113: Miles to Kilometers 29 challenge-113

--description--

Given a distance in miles as a number, return the equivalent distance in kilometers.

  • The input will always be a non-negative number.
  • 1 mile equals 1.60934 kilometers.
  • Round the result to two decimal places.
  • Remove unnecessary trailing zeros from the rounded result.

--hints--

convert_to_km(1) should return 1.61.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert_to_km(1), 1.61)`)
}})

convert_to_km(21) should return 33.8.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert_to_km(21), 33.8)`)
}})

convert_to_km(3.5) should return 5.63.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert_to_km(3.5), 5.63)`)
}})

convert_to_km(0) should return 0.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert_to_km(0), 0)`)
}})

convert_to_km(0.621371) should return 1.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert_to_km(0.621371), 1)`)
}})

--seed--

--seed-contents--

def convert_to_km(miles):

    return miles

--solutions--

def convert_to_km(miles):
    km = miles * 1.60934
    return round(km, 2)