Whose Error Is It?
Python printed this
UnboundLocalError: local variable 'total' referenced before assignment
What it meansPython treats total as local to the function because it is assigned there, but the code reads it before any assignment runs.
The first thing to checkUsually total is defined at module level and modified inside a function; initialize it inside the function or declare it global or nonlocal.