Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions rock-papper-scissors/main.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import random
import random


def winner(user, cpu):
#in cases where CPU is winner
if (user == "Rock" and cpu == "Paper") or (user == "Paper" and cpu == "Scissor") or (user == "Scissor" and cpu == "Rock"):
return "\nUser : " + user + "\nCPU : " + cpu + "\nWinner : CPU"

#in cases where User is winner
elif(cpu == "Rock" and user == "Paper") or (cpu == "Paper" and user == "Scissor") or (cpu == "Scissor" and user == "Rock"):
return "\nUser : " + user + "\nCPU : " + cpu + "\nWinner : User"

#in cases of ties
elif user == cpu:
return "\nUser : " + user + "\nCPU : " + cpu + "\nWinner : Draw"


#list of options program uses
options = ["Rock", "Paper", "Scissor"]

while True:
UI = input("\nEnter Your Choice (rock, paper, scissor) : ").title()

#program continues
if UI not in options:
continue
continue
print(winner(UI, random.choice(options)))
Comment on lines 22 to 24
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Give feedback on invalid input before continuing.

At Line 22, invalid choices are silently ignored, which can feel broken to users. Print a short validation message before continue.

Proposed UX fix
     if UI not in options:
-        continue `#program` continues
+        print("Invalid choice. Please enter rock, paper, or scissor.")
+        continue
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if UI not in options:
continue
continue #program continues
print(winner(UI, random.choice(options)))
if UI not in options:
print("Invalid choice. Please enter rock, paper, or scissor.")
continue
print(winner(UI, random.choice(options)))
🧰 Tools
🪛 Ruff (0.15.6)

[error] 23-23: Standard pseudo-random generators are not suitable for cryptographic purposes

(S311)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rock-papper-scissors/main.py` around lines 21 - 23, Invalid user choices are
currently ignored silently; before the continue in the input loop (when checking
if UI not in options) print a short validation message that includes the invalid
input (UI) and the accepted options or a hint, then continue; update the
conditional that references UI and options and the place calling winner(...) so
the message appears just before the existing continue to inform the user of the
bad input.


YN = input("\nPlay Again? (yes/no) : ").lower()
if YN == "no":
break
break