In the code below: highly simplified. I get ZeroDivisionError: float division
Any value below one gives errors. Other times 5/365 gives the error.
How do I fix?
import math
def top( t):
return ((.3 / 2) * t) / (.3 * math.sqrt(t))
t = 365/365
top= top(t)
print (top)
The problem is here:
You are dividing two integers, so python is using integer division. In integer division, the quotient is rounded down. For example,
364/365would be equal to0. (365/365works because it is equal to1, which is still1rounded down.)Instead, use float division, like so.