When teaching a class, it's important to take the students' averages in order to assign grades.
5 / 2 # 2 5.0 / 2 # 2.5 float(5) / 2 # 2.5
The above example is a reminder of how division works in Python.
- When you divide an integer by another integer, the result is always an integer (rounded down, if needed).
- When you divide a float by an integer, the result is always a float.
- To divide two integers and end up with a float, you must first use
float()to convert one of the integers to a float.