From e1b023cfa92c8ceaff32676626ba84903b718db1 Mon Sep 17 00:00:00 2001 From: ShaneWD <70982928+ShaneWD@users.noreply.github.com> Date: Thu, 3 Dec 2020 19:21:52 -0500 Subject: [PATCH] It is possible to land a the coin on its side. - According to the following study, a nickel can land on its side 1 out of 6000 times: https://ui.adsabs.harvard.edu/abs/1993PhRvE..48.2547M/abstract . I added this feature to the code. It chooses a number out of 6000, if it is less than 3000, it is tails, and if it is more than 3,000 it is heads. However, if the number is exactly 3000, this means that the coin landed on its side. - I also put the bulk of the code in a while loop so the user does not have to restart the program every single time. - Lastly, now the program does not crash if the user types in an invalid value. It now just asks the user to type in a valid number, and then it loops back. (p.s, a seed isn't really random, because a seed value of, let's say 7, will get you the same outcome every time. It should choose a random number/outcome without the seed being a variable) --- flip-a-coin.py | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/flip-a-coin.py b/flip-a-coin.py index 4384c76..27d9763 100644 --- a/flip-a-coin.py +++ b/flip-a-coin.py @@ -1,15 +1,27 @@ -print("#################") -print("## FLIP A COIN ##") -print("#################") + +print(""" +################# +## FLIP A COIN ## +################# +""") import random -test_seed = int(input("Create a seed number: ")) -random.seed(test_seed) - - -test_seed = random.randint(0, 1) -if test_seed == 1: - print("Heads") -else: - print("Tails") +while True: + try: + test_seed = int(input("Create a seed number: ")) + random.seed(test_seed) + test_seed = random.randint(0, 5999) + if test_seed > 2999: + print("Heads") + elif test_seed < 2999: + print("Tails") + else: + print(""" +Your coin landed on its side! +The odds of this happening to a nickel is 1 out of 6000 tosses +or 0.0167% +""") + except ValueError: + print("Please enter a number") +