当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python Kilometers转Miles用法及代码示例


千米是公制中的长度单位,相当于 1000 米。

英里也是长度单位,等于 1760 码。

例:

Input:5.5 
Output:3.418 

Input:6.5
Output:4.039

公式:

1 kilometer equals 0.62137 miles.
Miles = kilometer * 0.62137   
Kilometer = Miles / 0.62137

# Python3 program to convert
# kilometers to miles
  
# driver code
kilometers = 5.5
  
# conversion factor
conv = 0.621371
  
# calculate miles
miles = kilometers * conv
print('%0.3f kilometers is equal to %0.3f miles' %(kilometers,miles))
  
kilometers = 6.5
  
# calculate miles
miles = kilometers * conv
print('%0.3f kilometers is equal to %0.3f miles' %(kilometers,miles))

输出:

5.500 kilometers is equal to 3.418 miles
6.500 kilometers is equal to 4.039 miles


注:本文由纯净天空筛选整理自Shivani Ghughtyal大神的英文原创作品 Python Program to convert Kilometers to Miles。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。