Why do these scores need to be saved as floats?

Question

Why do these scores need to be saved as floats?

Answer

Later on in this project we’ll be creating a function to average the grades earned by each student. To average numbers, if we worked with integers, we would get inaccurate results because of how integers divide. Using floats ensures that we return only the most accurate of averages!

5 Likes

What is the disadvantage of entering all numbers as floats?

1 Like

Since the scores are (presumably) presented as integers, it is mildly annoying to be required to add “dot zero” to each one. In Python 3, that would not be necessary, since “regular” division works as you would expect, and it is integer division that requires an extra keystroke…

I aren’t sure what you mean when you say ‘regular’ division - do you mean it would float if it needed to instead of rounding?

1 Like

In Python 3, the / operator returns a float

print(5/3)
'''Output:
1.6666666666666667
'''

… whereas, if you mean to use integer division, you must use //

print(5//3)
'''Output:
1
'''
4 Likes