From 97cfeebd846825a3d0b922b080df3b8ca5d755e8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?tom=C3=A1s=20zerolo?= Date: Sun, 20 Nov 2022 16:35:22 +0100 Subject: [PATCH] Two off-by-one errors --- coinflip-histo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coinflip-histo.py b/coinflip-histo.py index 24dfc9a..2a737ce 100755 --- a/coinflip-histo.py +++ b/coinflip-histo.py @@ -5,7 +5,7 @@ from random import random import matplotlib.pyplot as plot def flipcoins (n): - return [int(2*random()) for i in range(n-1)] + return [int(2*random()) for i in range(n)] if len(sys.argv) != 3: print(f"Usage: {sys.argv[0]} \n") @@ -14,7 +14,7 @@ if len(sys.argv) != 3: flips = int(sys.argv[1]) repeats = int(sys.argv[2]) -vals = [sum(flipcoins(flips)) for i in range(repeats - 1)] +vals = [sum(flipcoins(flips)) for i in range(repeats)] plot.hist(vals, bins=flips, align='left') plot.show() -- 2.30.2