Skip to content

Commit 69422a1

Browse files
fix: re-prompt on invalid input in Rock-Paper-Scissors instead of exiting
1 parent 07f9b0f commit 69422a1

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

games/Rock-Paper-Scissor/Rock-Paper-Scissor.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,18 @@
2626
computer = random.randint(1, 3)
2727

2828
if value not in valid:
29-
Flag = False
30-
print('❌ Invalid choice! Rerun the game...\n')
31-
32-
elif Flag:
33-
print(f'\n👤 You chose: {key[valid[value]]}')
34-
print(f'🤖 Computer chose: {key[computer]}\n')
35-
36-
if (valid[value] == 1 and computer == 2) or (valid[value] == 2 and computer == 3) or (valid[value] == 3 and computer == 1):
37-
print('😢 You lost!! Better luck next time!\n')
38-
elif valid[value] == computer:
39-
print("🤝 It's a Tie!! Great minds think alike!\n")
40-
else:
41-
print('🎉 You won!! Congratulations!\n')
29+
print('❌ Invalid choice! Please enter r, p, or s. Try again.\n')
30+
continue
31+
32+
print(f'\n👤 You chose: {key[valid[value]]}')
33+
print(f'🤖 Computer chose: {key[computer]}\n')
34+
35+
if (valid[value] == 1 and computer == 2) or (valid[value] == 2 and computer == 3) or (valid[value] == 3 and computer == 1):
36+
print('😢 You lost!! Better luck next time!\n')
37+
elif valid[value] == computer:
38+
print("🤝 It's a Tie!! Great minds think alike!\n")
39+
else:
40+
print('🎉 You won!! Congratulations!\n')
4241

4342
response = str(input('Continue playing? Yes(y) or No(n): ')).lower()
4443

0 commit comments

Comments
 (0)