Skip to content

Improve Rock Paper Scissors input handling and game logic #45

Description

@Abobakr-Mahmoud-Momtaz

I made some improvements to the Rock Paper Scissors game and wanted to share my approach.

One of the changes I made was adding .strip() to the user input:

user_input = input("Type Rock/Paper/Scissors or Q to quit: ").lower().strip()

I also refactored the win conditions using lists and a loop, and added separate handling for wins, losses, and draws.

Here is the approach I came up with:

one_condition_user_win = ["rock", "paper", "scissors"]
two_condition_user_win = ["scissors", "rock", "paper"]

for i in range(len(options)):
    if user_input == one_condition_user_win[i] and computer_pick == two_condition_user_win[i]:
        user_wins += 1
        user_won = True
        break

if user_won:
    print("You won!")
elif user_input == computer_pick:
    print("You drew.")
else:
    print("You lost!")
    computer_wins += 1

I wanted to share this as a possible beginner-friendly way to organize the game logic.

code.py

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions