7/23/2023 0 Comments Slack coin flipPrint("Congratulations! After", len(guesses), "you guessed correctly!") Return guesses # Returning guesses means we won While True: # We're just going to return, so we don't need a condition With how you have it set up now, I'm going to disregard cancelling since that will require some broader changes to accommodate, and it's highly unlikely that the user will have to guess more than a few times. I'd have a function that returns a list of guesses made until a correct guess was made. I think that whole game loop part should be taken out into it's own function though beyond what you've already done. Or, more idiomatically: if not guesses: # "If no(t) guesses (have been made)" To check if it was their first guess or not, you can do: if len(guesses) = 0: If you need to find out how many guesses were made, you can just do len(guesses). Notice now though that guess_count will always be equal to the length of guesses, so it isn't needed. If you change it to append to guesses on both right and wrong answers, you'll have this: guess_count = 0 I think it makes more sense to add to the guess_count regardless, and start it at 0.īut then you're also only adding to guesses on wrong answers too. Regardless of if they were right or wrong though, they still made a guess. You're only increasing guess_count if the guess was wrong. Then later: if user_input != random_flip(): In coin_flip_game you have guess_count = 1 #guesses set to 1 so that program considers 1st guess Std_decision = decision.upper() # discards all but the first letter 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. I think I finally finished a small coin flip project I found online.
0 Comments
Leave a Reply. |