From 82531874d5d13b9bc60e2acdc143733e5b158def Mon Sep 17 00:00:00 2001 From: eklairs Date: Tue, 30 Apr 2024 08:19:54 +0530 Subject: [PATCH] fix: division by zero error when calculating accuracy (#86) --- smassh/src/stats_tracker.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/smassh/src/stats_tracker.py b/smassh/src/stats_tracker.py index 4d7cad20..f1207908 100644 --- a/smassh/src/stats_tracker.py +++ b/smassh/src/stats_tracker.py @@ -108,7 +108,13 @@ def raw_wpm(self) -> int: @property def accuracy(self) -> int: - accuracy = (self.correct / (self.correct + self.incorrect)) * 100 + total_typed = self.correct + self.incorrect + + if total_typed == 0: + return 0 + + accuracy = (self.correct / total_typed) * 100 + return round(accuracy) @property