我正试图理解这个代码的一个简单问题。
对于此代码的最后一行,我不明白为什么print语句中有0.3f。 "%"是有道理的,因为变量千米和英里被插入到声明中,但0.3f让我有点失落。
# Program to convert kilometers into miles
# Input is provided by the user in kilometers
# take input from the user
kilometers = float(input('How many kilometers?: '))
# conversion factor
conv_fac = 0.621371
# calculate miles
miles = kilometers * conv_fac
print('%0.3f kilometers is equal to %0.3f miles' %(kilometers,miles))
答案 0 :(得分:1)
.3
定义精度。这是小数点后要打印的位数(默认情况下,这是6)