0

just a quick question on this code that I am trying to understand.

for the last line of this code I don't understand why there is a 0.3f in the print statement. The "%" makes sense because the variable kilometers and miles is being inserted inside the statement but, the 0.3f has me kind of lost.

# 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))
P Ramos
  • 31
  • 1
  • 2
  • 5

1 Answers1

2

.3 defines the precision. this is the number of digits to be printed after the decimal point (by default, this is 6)

h3n
  • 880
  • 1
  • 10
  • 26