![]() I'd at least upper-case their input, and unless you really needed them to be specific, only keep the first letter: decision = input("You guessed wrong, do you want to continue? Yes or No ") This is pretty exact text to expect from the user. Print("Your previous guesses were: ", guesses)Īfter getting user input, you check it by doing decision = "Yes". Print("Congratulations! After ", guess_count, "you guessed correctly!") Print("Congratulations, you guessed correctly on your first try!") Guesses = #list of guesses made by userįirst_try = True #Variable to determine whether first try of user or notĬancel_game = False #Variable to determine whether game was cancelledĭecision = input("You guessed wrong, do you want to continue? Yes or No ") Guess_count = 1 #guesses set to 1 so that program considers 1st guess. Random_choice = random.choice()ĭef user_choice(): #function to ensure a valid input from the user, and returns that input.ĭef coin_flip_game(): #function that plays the coin flip game. import randomĭef random_flip(): #function to generate random Heads or Tails output py file which hopefully you can access here. This is my first time really using GitHub, but I included the. As a user I want to be able to quit the game or go again after each cycle.As a user I want to clearly see the updated guess history (correct count/total count).As a user I want to clearly see whether or not I guessed correctly.As a user I want to clearly see the result of the coin flip.As a user I want to be able to guess the outcome of a random coin flip (heads/tails).Since I'm studying by myself using Head First and Code Academy any feedback would be very very helpful! However, I'm pretty confident this is far from the optimal solution and would really appreciate any feedback on how this could be improved. (There can be from $0$ through $16$ coins after $4$ steps, which is all I needed.) The probability of transition from $i$ coins to $j$ coins is $0$ if $j$ is odd and $\right)$.I think I finally finished a small coin flip project I found online. I set this up as a Markov process where the state is the number of coins. I confirmed Michael's answer by the brute-force approach suggested by Calvin and Wim in their answers. This is too long for a reply to my earlier comment, and since it provides an alternate answer, I'm posting it that way. Does anyone have any other ideas, or perhaps a formula to solve this problem? But I'm just not able to calculate how many possible ways exist to get to each amount of total coins by the end. What I've tried to do is to find the total amount of possibilities for each amount of coins by the 5th moment, and then multiply that by the probability that all coins will be vanished on the 5th moment. I've taken a few approaches to this problem. What is the probability that exactly after 5 minutes (that's 5 sets of flips), that the process will have stopped (so no earlier or no later)? Once there are no more coins remaining, the process stops. (Note any new coins are not flipped until the next moment). ![]() But for every tails that is flipped, a coin is lost. For each heads that is flipped, you get another coin. ![]() At the end of each minute, all coins are flipped simultaneously. ![]() So my friend gave me this question this other day, and I've tried to start it (I'll show my logic below), but I couldn't find any efficient way to do the problem. ![]()
0 Comments
Leave a Reply. |