Python-programming-exercises icon indicating copy to clipboard operation
Python-programming-exercises copied to clipboard

create a rock paper scissors game in python

Open SHAHAD-ALSULAMI opened this issue 3 years ago • 3 comments

SHAHAD-ALSULAMI avatar May 22 '22 20:05 SHAHAD-ALSULAMI

You may have played rock paper scissors before. Maybe you’ve used it to decide who pays for dinner or who gets first choice of players for a team.

If you’re unfamiliar, rock paper scissors is a hand game for two or more players. Participants say “rock, paper, scissors” and then simultaneously form their hands into the shape of a rock (a fist), a piece of paper (palm facing downward), or a pair of scissors (two fingers extended). The rules are straightforward:

Rock smashes scissors. Paper covers rock. Scissors cut paper.

SHAHAD-ALSULAMI avatar May 22 '22 21:05 SHAHAD-ALSULAMI

Now that you have the rules down, you can start thinking about how they might translate to Python code

SHAHAD-ALSULAMI avatar May 22 '22 21:05 SHAHAD-ALSULAMI

import random

user_action = input("Enter a choice (rock, paper, scissors): ") possible_actions = ["rock", "paper", "scissors"] computer_action = random.choice(possible_actions) print(f"\nYou chose {user_action}, computer chose {computer_action}.\n")

if user_action == computer_action: print(f"Both players selected {user_action}. It's a tie!") elif user_action == "rock": if computer_action == "scissors": print("Rock smashes scissors! You win!") else: print("Paper covers rock! You lose.") elif user_action == "paper": if computer_action == "rock": print("Paper covers rock! You win!") else: print("Scissors cuts paper! You lose.") elif user_action == "scissors": if computer_action == "paper": print("Scissors cuts paper! You win!") else: print("Rock smashes scissors! You lose.")

SHAHAD-ALSULAMI avatar May 22 '22 21:05 SHAHAD-ALSULAMI

i would suggest this repository's method of doing this tbh,https://github.com/superking816pro/rock-paper-sissor-spock

superking816pro avatar Dec 05 '22 14:12 superking816pro