()
| 11 | |
| 12 | |
| 13 | def start_game(): |
| 14 | random_number = int(random.randint(1, 10)) |
| 15 | print("Hello traveler! Welcome to the game of guesses!") |
| 16 | player_name = input("What is your name? ") |
| 17 | wanna_play = input( |
| 18 | "Hi, {}, would you like to play the guessing game? (Enter Yes/No) ".format( |
| 19 | player_name |
| 20 | ) |
| 21 | ) |
| 22 | # Where the show_score function USED to be |
| 23 | attempts = 0 |
| 24 | show_score() |
| 25 | while wanna_play.lower() == "yes": |
| 26 | try: |
| 27 | guess = input("Pick a number between 1 and 10 ") |
| 28 | if int(guess) < 1 or int(guess) > 10: |
| 29 | raise ValueError("Please guess a number within the given range") |
| 30 | if int(guess) == random_number: |
| 31 | print("Nice! You got it!") |
| 32 | attempts += 1 |
| 33 | attempts_list.append(attempts) |
| 34 | print("It took you {} attempts".format(attempts)) |
| 35 | play_again = input("Would you like to play again? (Enter Yes/No) ") |
| 36 | attempts = 0 |
| 37 | show_score() |
| 38 | random_number = int(random.randint(1, 10)) |
| 39 | if play_again.lower() == "no": |
| 40 | print("That's cool, have a good one!") |
| 41 | break |
| 42 | elif int(guess) > random_number: |
| 43 | print("It's lower") |
| 44 | attempts += 1 |
| 45 | elif int(guess) < random_number: |
| 46 | print("It's higher") |
| 47 | attempts += 1 |
| 48 | except ValueError as err: |
| 49 | print("Oh no!, that is not a valid value. Try again...") |
| 50 | print("({})".format(err)) |
| 51 | else: |
| 52 | print("That's cool, have a good one!") |
| 53 | |
| 54 | |
| 55 | if __name__ == "__main__": |
no test coverage detected