From 4a73d60c198ce8b3b0f9444a48102e9d3e9076d6 Mon Sep 17 00:00:00 2001 From: ColorfulQuark <108406142+ColorfulQuark@users.noreply.github.com> Date: Sat, 2 Jul 2022 09:41:46 -0400 Subject: [PATCH 1/4] Update higher-of-two-rolls.py --- higher-of-two-rolls.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/higher-of-two-rolls.py b/higher-of-two-rolls.py index e75264b..b07a20c 100644 --- a/higher-of-two-rolls.py +++ b/higher-of-two-rolls.py @@ -1,15 +1,8 @@ -import random +from random import randint +from statistics import mean number_of_sides = int(input("How many sides on your dice? ")) -sum_of_results = 0.0 - -trials = 0 -while trials < 10**6: - sum_of_results += max([int(random.random()*number_of_sides)+1,int(random.random()*number_of_sides)+1]) - trials += 1 - -print("Average result of rolling two and taking the highest is about {0}".format(sum_of_results/trials)) - - +avg = mean([max(randint(1,number_of_sides), randint(1,number_of_sides)) for _ in range(10**6)]) +print(f"Average result of rolling two and taking the highest is about {avg}") From 3e1debcf95c5c2cd6ce5560fe5a77e225eaa8d18 Mon Sep 17 00:00:00 2001 From: ColorfulQuark <108406142+ColorfulQuark@users.noreply.github.com> Date: Sat, 2 Jul 2022 09:44:40 -0400 Subject: [PATCH 2/4] Update higher-of-two-rolls.py --- higher-of-two-rolls.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/higher-of-two-rolls.py b/higher-of-two-rolls.py index b07a20c..8cf6d66 100644 --- a/higher-of-two-rolls.py +++ b/higher-of-two-rolls.py @@ -1,3 +1,5 @@ +# Slightly less terrible code + from random import randint from statistics import mean From c5de54cffd6bde304e8fa070152ce3a6f8af4644 Mon Sep 17 00:00:00 2001 From: ColorfulQuark <108406142+ColorfulQuark@users.noreply.github.com> Date: Sat, 2 Jul 2022 09:46:51 -0400 Subject: [PATCH 3/4] Delete higher-of-two-rolls.py --- higher-of-two-rolls.py | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 higher-of-two-rolls.py diff --git a/higher-of-two-rolls.py b/higher-of-two-rolls.py deleted file mode 100644 index 8cf6d66..0000000 --- a/higher-of-two-rolls.py +++ /dev/null @@ -1,10 +0,0 @@ -# Slightly less terrible code - -from random import randint -from statistics import mean - -number_of_sides = int(input("How many sides on your dice? ")) - -avg = mean([max(randint(1,number_of_sides), randint(1,number_of_sides)) for _ in range(10**6)]) - -print(f"Average result of rolling two and taking the highest is about {avg}") From 21366d949f158c7c8afe24e8c2c88a35ae527ab1 Mon Sep 17 00:00:00 2001 From: ColorfulQuark <108406142+ColorfulQuark@users.noreply.github.com> Date: Sat, 2 Jul 2022 09:47:45 -0400 Subject: [PATCH 4/4] Create Slightly less terrible --- Slightly less terrible | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Slightly less terrible diff --git a/Slightly less terrible b/Slightly less terrible new file mode 100644 index 0000000..b07a20c --- /dev/null +++ b/Slightly less terrible @@ -0,0 +1,8 @@ +from random import randint +from statistics import mean + +number_of_sides = int(input("How many sides on your dice? ")) + +avg = mean([max(randint(1,number_of_sides), randint(1,number_of_sides)) for _ in range(10**6)]) + +print(f"Average result of rolling two and taking the highest is about {avg}")