From cb75b21b01b20e01aa12234ba58f5218aaf4924f Mon Sep 17 00:00:00 2001 From: Hamza Faran Date: Sun, 17 Dec 2017 23:29:39 -0800 Subject: [PATCH] Avoid zero division --- progressive/bar.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/progressive/bar.py b/progressive/bar.py index 9a72782..565193a 100644 --- a/progressive/bar.py +++ b/progressive/bar.py @@ -351,8 +351,9 @@ def draw(self, value, newline=True, flush=True): # the terminal since the code is mostly written dynamically # and many attributes and dynamically calculated properties. self._measure_terminal() - - amount_complete = value / self.max_value + + # To avoid zero division, set amount_complete to 100% if max_value has been stupidly set to 0 + amount_complete = 1.0 if self.max_value == 0 else value / self.max_value fill_amount = int(floor(amount_complete * self.max_width)) empty_amount = self.max_width - fill_amount