Skip to content

Commit 6589c3a

Browse files
author
Niloofar
committed
improve play again confirmation logic
1 parent e967746 commit 6589c3a

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Python-Scripts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 3ad8293b0b314dfc0724b03d772dcef31e48cf15

Rock Paper Scissors -New/rps.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import random
22

3+
choices = ["rock", "paper", "scissors", "lizard", "spock"]
34

45
def get_user_choice():
5-
choices = ["rock", "paper", "scissors", "lizard", "spock"]
66
user_choice = input("Enter your choice (rock, paper, scissors, lizard, spock): ").lower()
77
while user_choice not in choices:
88
user_choice = input("Invalid choice. Please enter rock, paper, scissors, lizard, or spock: ").lower()
99
return user_choice
1010

1111

1212
def get_computer_choice():
13-
choices = ["rock", "paper", "scissors", "lizard", "spock"]
1413
return random.choice(choices)
1514

1615

@@ -76,12 +75,16 @@ def play_game():
7675
print(f"User: {user_score}")
7776
print(f"Computer: {computer_score}")
7877
print(f"Ties: {ties}")
78+
79+
while True:
80+
play_again = input("\nDo you want to play again? (y/n): ").lower()
81+
if play_again in ["y", "n"]:
82+
break
83+
print("Invalid input. Please enter 'y' or 'n'.")
7984

80-
play_again = input("\nDo you want to play again? (y/n): ").lower()
8185
if play_again != "y":
8286
print("Thanks for playing!")
8387
break
8488

85-
8689
if __name__ == "__main__":
8790
play_game()

0 commit comments

Comments
 (0)