0

i have a code as seen below but i didn't understand what is the meaning of 3.2f in the last two lines. can somebody help me about this situation?

km_start = int(input("insert beginning kilometers: "))
km_stop = int(input("insert ending kilometers: "))
working_days = int(input("insert the number of working days: "))
km_home_work = int(input("insert the home-work discance: "))
km_total = km_stop - km_start
km_work = working_days * (km_home_work *2)
km_not_work = km_total - km_work
km_work = 100 * (km_work/km_total)
km_not_work = 100 * (km_not_work/km_total)
print(10*"-")
print(f"car used for work activities: {km_work:3.2f} %")
print(f"car used for not work activities: {km_not_work:3.2f} %")
wjandrea
  • 28,235
  • 9
  • 60
  • 81
kerooo
  • 9
  • 1
  • 1
    This might help: https://stackoverflow.com/a/47775345/7789963 – medium-dimensional Oct 01 '22 at 20:36
  • See the docs: [Formatted string literals](https://docs.python.org/3/reference/lexical_analysis.html#formatted-string-literals) (f-strings) -> [format specifiers](https://docs.python.org/3/library/string.html#formatspec) -> *"`'f'` Fixed-point notation. ..."* – wjandrea Oct 01 '22 at 20:42
  • https://stackoverflow.com/questions/45310254/fixed-digits-after-decimal-with-f-strings – BeRT2me Oct 01 '22 at 20:43

1 Answers1

0

It means print as a floating point at least 3 wide and a precision of 2.

This is a format specifier of a floating point number with 2 decimals and at least one digit left of the decimal point.

The number 12.34567 would be displayed as 12.35. 5 would be displayed as 5.00.

Eftal Gezer
  • 191
  • 1
  • 8
  • Thank you so much for your respond. By the way what is the difference between 3.2f and 5.2f? When I write both, I get the same outputs, nothing changes. – kerooo Oct 02 '22 at 00:50
  • @KeremYıldırım It means at least 5 wide and a precision of 2. You probably get the same result because of the precision. – Eftal Gezer Oct 02 '22 at 15:54