-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathconvert_miles_to_kms.py
More file actions
28 lines (24 loc) · 1.14 KB
/
convert_miles_to_kms.py
File metadata and controls
28 lines (24 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
################################################################################
#
# Program: Convert Miles To Kilometers
#
# Description: Convert miles to kilometers using Python.
#
# YouTube Lesson: https://www.youtube.com/watch?v=StFx57DxND8
#
# Author: Kevin Browne @ https://portfoliocourses.com
#
################################################################################
# Prompt the user to enter the distance in miles using input(), the
# function will return the text entered by the user as a string, convert that
# string to a float value with float() and store it into miles (so that we
# can perform mathematical operations with the value).
miles = float(input("Miles: "))
# Convert the distance to kilometers and store it into the variable miles using
# the formula: https://en.wikipedia.org/wiki/Kilometre
kilometers = miles / 0.621371
# Output the text "Kilometers:" followed by the value in the variable kilometers
print("Kilometers:", kilometers)
# Alternatively, we could use an f-string to output the kilometers with
# 2 decimal digits of precision with .2 and in fixed-point notation with .2f
print(f"Kilometers: {kilometers:.2f}")