(Jun-11-2020, 09:02 PM)dgrunwal Wrote: Hmm, still receive ZeroDivisionError: division by zero, trying the following:
Look at @stullis' example and how it differ from your code:
from ast import literal_eval with open("C:\Dave\data.txt") as f : for line in f : name, values = line.split(' = ') values = literal_eval(values) print(f" District: {name}") try: print(f"Hal received {values[3]} votes AVG: - {values[3]/sum(values):.2%}).") except ZeroDivisionError: print('There are only zeros in values.'Note, I don't think
values[3]/sum(values)
would produce average value, if that is what you calculate AVG
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs