ZeroDivisionError float division by zero def main s enter
ZeroDivisionError: float division by zero >>> def main (): s = (\"enter the string\") words=re.sub(|[^\\W]\", \"\", s). Split() l = len (words) sum = 0 average = sum/float(1) for i in range (0, 1): sum = sum + len (words[i]) print (\"average length is\", average) >>> main () Traceback (most recent call last): File \" >>|
Solution
You are dividing by zero.
first of all you are calculating the average before the sum is not even calculated
first calculate the total sum.
then use below statement.
if sum!=0:
average = sum/float(l)
