314,476 views
38 votes
38 votes
Write Python code to convert miles to kilometers. This does not need to be written in a Python function, but it should use the input()function. Running your code should produce a statement asking for the user to enter a number (in miles). Then it should print out a sentence of what that number is in kilometers. Use the conversion rate of 1 mile

User Recognosco
by
2.7k points

2 Answers

18 votes
18 votes

Answer:

It can be so frustrating that the entire planet can't just agree on one system of measurement, whether it relates to measuring distances, weights, temperatures, etc (for the record...same goes for which side of the road everyone drives on). If every country used the same units of measurement, then these formulas would be useless and obsolete, but until then, it might be a good idea to understand how to convert miles to kilometers, and vice versa. If you're a Python developer, then knowing how to write the formulas in Python might be especially useful. Keep reading to see just how it's done.

Converting miles to km isn't especially difficult. To do a rough estimate of the conversion in your head, all you really need to remember is that a mile equals about 1.6 kilometers (or that a kilometer is approximately 2/3 of a mile). When trying to find the correct conversion using a formula, we must use the more precise conversion factor, which is equal to 0.62137119.

To convert miles to kilometers, the formula is very straightforward. All you need to do is divide the number of miles by the conversion factor. To see how it would look written out in Python, check out the example below:

Step-by-step explanation:

User Dustinevan
by
3.5k points
7 votes
7 votes

Answer:

All you need to convert the Python code is TWO variables, a Outcome variable and a income variable.

Step-by-step explanation:

i Hope this helps u

User Webbiedave
by
2.4k points