diff options
author | Raymond Hettinger <python@rcn.com> | 2016-11-17 05:34:39 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2016-11-17 05:34:39 (GMT) |
commit | e92245b3dfecad8b91f71d289dea3029fafe0797 (patch) | |
tree | 6e674069e4d87312430e43fcfdb214ff3d735cea | |
parent | cb9d10fecb018c6a9551524e583a989cfcb68b9c (diff) | |
parent | 2589ee3e2b8726f41a2712ee035219d2a9696876 (diff) | |
download | cpython-e92245b3dfecad8b91f71d289dea3029fafe0797.zip cpython-e92245b3dfecad8b91f71d289dea3029fafe0797.tar.gz cpython-e92245b3dfecad8b91f71d289dea3029fafe0797.tar.bz2 |
merge
-rw-r--r-- | Doc/library/random.rst | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Doc/library/random.rst b/Doc/library/random.rst index edf76d7..72d6a39 100644 --- a/Doc/library/random.rst +++ b/Doc/library/random.rst @@ -344,15 +344,15 @@ Basic usage:: >>> deck ['king', 'queen', 'ace', 'jack'] - >>> random.sample([1, 2, 3, 4, 5], 3) # Three samples without replacement + >>> random.sample([1, 2, 3, 4, 5], k=3) # Three samples without replacement [4, 1, 5] >>> # Six weighted samples with replacement >>> choices(['red', 'black', 'green'], [18, 18, 2], k=6) ['red', 'green', 'black', 'black', 'red', 'black'] - # Probability of getting 5 or more heads from 7 spins of a biased coin - # that settles on heads 60% of the time. + # Probability of getting 5 or more heads from 7 spins + # of a biased coin that settles on heads 60% of the time. >>> n = 10000 >>> cw = [0.60, 1.00] >>> sum(choices('HT', cum_weights=cw, k=7).count('H') >= 5 for i in range(n)) / n @@ -369,5 +369,6 @@ sample of size five:: data = 1, 2, 4, 4, 10 means = sorted(mean(choices(data, k=5)) for i in range(20)) - print('The sample mean of {:.1f} has a 90% confidence interval ' - 'from {:.1f} to {:.1f}'.format(mean(data), means[1], means[-2])) + print(f'The sample mean of {mean(data):.1f} has a 90% confidence ' + f'interval from {means[1]:.1f} to {means[-2]:.1f}') + |