當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。