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
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: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:
I wanted to share this as a possible beginner-friendly way to organize the game logic.
code.py