Convert Kilometers to Miles Converter

PythonPythonBeginner
Practice Now

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.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL python(("`Python`")) -.-> python/BasicConceptsGroup(["`Basic Concepts`"]) python(("`Python`")) -.-> python/FunctionsGroup(["`Functions`"]) python/BasicConceptsGroup -.-> python/comments("`Comments`") python/FunctionsGroup -.-> python/function_definition("`Function Definition`") subgraph Lab Skills python/comments -.-> lab-13680{{"`Convert Kilometers to Miles Converter`"}} python/function_definition -.-> lab-13680{{"`Convert Kilometers to Miles Converter`"}} end

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.

Other Python Tutorials you may like