{"id":6814,"date":"2021-09-30T11:30:43","date_gmt":"2021-09-30T06:00:43","guid":{"rendered":"https:\/\/python-programs.com\/?p=6814"},"modified":"2021-11-22T18:35:28","modified_gmt":"2021-11-22T13:05:28","slug":"python-program-to-convert-kilometers-to-miles-and-vice-versa","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-convert-kilometers-to-miles-and-vice-versa\/","title":{"rendered":"Python program to Convert Kilometers to Miles and Vice Versa"},"content":{"rendered":"
Let us begin with the fundamentals, namely understanding the significance of these measuring units. The units of length are the kilometer\u00a0and the mile.<\/p>\n
Examples:<\/strong><\/p>\n 1)km to miles<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n 2)miles to km\u00a0<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n Formula :<\/strong><\/p>\n As a result, the value 0.62137 can be regarded as the conversion factor or ratio for the conversion to occur.<\/p>\n Algorithm:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Formula :<\/strong><\/p>\n As a result, the value 0.62137 can be regarded as the conversion factor or ratio for the conversion to occur.<\/p>\n Algorithm:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n Let us begin with the fundamentals, namely understanding the significance of these measuring units. The units of length are the kilometer\u00a0and the mile. Examples: 1)km to miles Input: distance =6.5 km Output: The given distance 6.5 km in miles= 4.038905 miles 2)miles to km\u00a0 Input: distance =6.5 miles Output: The given distance 6.5 miles in …<\/p>\ndistance =6.5 km<\/pre>\n
The given distance 6.5 km in miles= 4.038905 miles<\/pre>\n
distance =6.5 miles<\/pre>\n
The given distance 6.5 miles in km= 10.460756071261889 km<\/pre>\n
Conversion of Kilometers to Miles and Vice Versa<\/h2>\n
\n
1)Converting kilometers to miles<\/h3>\n
1 kilometer = 0.62137 miles.<\/pre>\n
\n
# given the distance in km\r\ndistkm = 6.5\r\n# conversion ratio\r\nconversion_ratio = 0.62137\r\n# converting the km to miles\r\ndistmiles = distkm*conversion_ratio\r\n# print the distance in miles\r\nprint(\"The given distance\", distkm, \"km\", \"in miles=\", distmiles,\"miles\")\r\n<\/pre>\n
The given distance 6.5 km in miles= 4.038905 miles<\/pre>\n
2)Converting miles to kilometers<\/h3>\n
1 mile= km \/ 0.62137<\/pre>\n
\n
# given the distance in miles\r\ndistmiles = 6.5\r\n# conversion ratio\r\nconversion_ratio = 0.62137\r\n# converting the miles to km\r\ndistkm = distmiles\/conversion_ratio\r\n# print the distance in km\r\nprint(\"The given distance\", distmiles, \"miles\", \"in km=\", distkm, \"km\")\r\n<\/pre>\n
The given distance 6.5 miles in km= 10.460756071261889 km<\/pre>\n
\n