Hmm, still receive ZeroDivisionError: division by zero, trying the following:
File "C:/Python37-32/read1.py", line 9, in <module>
print(f"Hal received {values[3]} votes AVG: - {values[3] / sum(values):.2%}).")
ZeroDivisionError: division by zero
I think I am having trouble including the for loop in the code above when division by zero occurs:
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}") print(f"Hal received {values[3]} votes AVG: - {values[3] / sum(values):.2%}).") try : print(f"Hal received {values[3]}") except ZeroDivisionError : ...Traceback (most recent call last):
File "C:/Python37-32/read1.py", line 9, in <module>
print(f"Hal received {values[3]} votes AVG: - {values[3] / sum(values):.2%}).")
ZeroDivisionError: division by zero
I think I am having trouble including the for loop in the code above when division by zero occurs:
#this works try: (print (1/0)) except ZeroDivisionError: print ("You can't divide by zero, you're silly.")