# HG changeset patch # User souliane # Date 1460890844 -7200 # Node ID 44342730df661b338fe98a5c9f78ea29981f6fbe # Parent 2c55e7e99ef323aa763b2317f9f5a188f72b1a67 jp (cmd/roster): fixes division by zero exceptions fix bug 135 diff -r 2c55e7e99ef3 -r 44342730df66 frontends/src/jp/cmd_roster.py --- a/frontends/src/jp/cmd_roster.py Sat Mar 26 18:43:54 2016 +0100 +++ b/frontends/src/jp/cmd_roster.py Sun Apr 17 13:00:44 2016 +0200 @@ -149,8 +149,16 @@ print "Contacts with no subscription at all: %d" % no_sub print print "Total number of groups: %d" % len(unique_groups) - print "Average contacts per group: %.1f" % (float(total_group_subscription) / len(unique_groups)) - print "Average groups' subscriptions per contact: %.1f" % (float(total_group_subscription) / len(contacts)) + try: + contacts_per_group = float(total_group_subscription) / len(unique_groups) + except ZeroDivisionError: + contacts_per_group = 0 + print "Average contacts per group: {:.1f}".format(contacts_per_group) + try: + groups_per_contact = float(total_group_subscription) / len(contacts) + except ZeroDivisionError: + groups_per_contact = 0 + print "Average groups' subscriptions per contact: {:.1f}".format(groups_per_contact) print "Contacts not assigned to any group: %d" % no_group self.host.quit()