Floating-point arithmetic represents numbers with fractional components. Python provides float as both a numeric type and a constructor for converting values such as strings and integers into floating-point objects. section 2.0 section 2.18
Use floating-point values when a calculation requires fractional quantities, while watching for these practical concerns:
- Convert user input before arithmetic: input returns a string, so adding unconverted values concatenates strings instead of adding numbers. section 5.9
- Track both accumulated values and their count when calculating an average, and preserve floating-point inputs and outputs where required. section 2.10
- Treat floats as potentially inexact; explore Decimal when decimal input such as 0.1 and 0.2 must produce an accurate decimal sum. section 2.13
Average repeated run times
A run_timing function repeatedly asks for 10-kilometer run times until Enter is pressed, converts each response to a float, accumulates the values, counts the runs, and displays their average. Three entries—15, 20, and 10—produce an average of 15.0 over three runs. section 2.10
Enter 10 km run time: 15 Enter 10 km run time: 20 Enter 10 km run time: 10 Enter 10 km run time: <enter> Average of 15.0, over 3 runs
The sample interaction shows repeated floating-point input, termination with Enter, and an explicitly floating-point average. section 2.10



















