diff --git a/ScissorsRockPaper.py b/ScissorsRockPaper.py index 6e7b930..d0ba9ad 100644 --- a/ScissorsRockPaper.py +++ b/ScissorsRockPaper.py @@ -12,11 +12,14 @@ while game_status is True: # Due to game_status will be True all the time, we're putting the process in the while loop # The player will choose their figur here - player_choose = 0 - while player_choose not in(1,2,3): - player_choose = int(input("\n[1] Scissors | [2] Rock | [3] Paper\n")) - # Tip: \n is the standard newline character, which prints a new line after printing the opportunities to choose - player_figur = figure[player_choose - 1] + try: + player_choose = 0 + while player_choose not in(1,2,3): + player_choose = int(input("\n[1] Scissors | [2] Rock | [3] Paper\n")) + # Tip: \n is the standard newline character, which prints a new line after printing the opportunities to choose + player_figur = figure[player_choose - 1] + except: + continue # Should the player gives a wrong type, like a string e.g. we will catch the ValueError here # Figur the computer will choose randomly, for this process we're going to use our already imported random computer_figur = figure[random.randint(0, 2)] # Tip: Not "0,3" because you start count at zero in Python @@ -51,14 +54,17 @@ - choose_restart = "" # We're expecting a string, that's why we're defining it here + choose_restart = "" while choose_restart.lower() not in ("y", "n"): # We're using the builtin .lower() here, should the player send the letter in caps the input will be lowercase automatically # Tip: Should the player give us something else than "y" and "n", we'll show them the opportunities again = while loop # Tip: Don't forget that game_status is set to True already, due to that the game will start again choose_restart = input("\n[🔁] Restart the game? [y] YES | [n] NO\n") time.sleep(2) + if choose_restart == "y": + game_status = True + if choose_restart == "n": print("\n[✋] Alright! Game has been stopped, you can start it whenever you want again.\n") - time.sleep(5) - game_status = False # We'll stop the while loop with setting this to False, as mentioned above \ No newline at end of file + time.sleep(2) + game_status = False # We'll stop the while loop with setting this to False, as mentioned above