I’m do some calculations and append them to a list. However there are calculations that will cause a division by zero error. If that happens, I want to just append the word “error” in the list.
A sample code:
try:
for i in [1,2,3]:
z.append(i/(i-1))
except ZeroDivisionError:
z.append("error")
But the code I have stops once the error occurs so the list z would only have [“error”]. Is there a way to modify my code so that it continues until the end of the loop so z would contain [“error”, 1, 2]
1 Answer