Skip to content

create a rock paper scissors game in python #174

Open
@SHAHAD-ALSULAMI

Description

@SHAHAD-ALSULAMI
No description provided.

Activity

SHAHAD-ALSULAMI

SHAHAD-ALSULAMI commented on May 22, 2022

@SHAHAD-ALSULAMI
Author

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

SHAHAD-ALSULAMI commented on May 22, 2022

@SHAHAD-ALSULAMI
Author

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

SHAHAD-ALSULAMI

SHAHAD-ALSULAMI commented on May 22, 2022

@SHAHAD-ALSULAMI
Author

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.")

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

      create a rock paper scissors game in python · Issue #174 · zhiwehu/Python-programming-exercises