A Python float represents a number with a fractional part or a value written in scientific notation, such as 3.14 or 2.0e-8. Its precision depends on the underlying machine and is typically comparable to a C double. Unlike Python integers, floats do not have an unlimited range of precision. section 4.7
The operators and conversions most likely to matter are:
- Division with / returns a float even when both operands are integers: 5 / 2 gives 2.5. Use // when integer operands should produce a whole-number result: 5 // 2 gives 2. section 4.7
- An operation involving a float produces a float: 30000000000 * 3.0 gives 90000000000.0. float(200) gives 200.0; int(200.2) discards the fractional part and gives 200. section 4.7
- float('123.456') converts a numeric string. A string that cannot be interpreted as a number raises ValueError. section 6.4.2
Calculate an average
x = 3 y = 5 z = (x + y) / 2 z is 4.0. The parentheses make the addition happen before division; without them, the expression would be x + (y / 2). section 4.5
input() returns a string, so convert it with float() before using it as a float. When invalid input is possible, catch ValueError: a spreadsheet cell converter can return 0 for an empty cell and None for other nonnumeric text. section 4.9 section 14.2.9



















