Convert Kilometers to Miles Converter

Beginner

This tutorial is from open-source community. Access the source code

Introduction

In this challenge, you will be required to write a Python function that converts kilometers to miles. You will be given a distance in kilometers and you will need to return the equivalent distance in miles.

Km to Miles

Write a Python function called km_to_miles that takes a parameter km (a float) and returns the equivalent distance in miles (also a float). The conversion formula is mi = km * 0.621371.

def km_to_miles(km):
  return km * 0.621371
km_to_miles(8.1) ## 5.0331051

Summary

In this challenge, you have learned how to convert kilometers to miles using a simple formula. You have also written a Python function that implements this formula and returns the equivalent distance in miles.