Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Rock paper scissors in python. #2244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
67 changes: 67 additions & 0 deletions rock-paper-scissors/python/rock-paper-scissors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
""" Rock Paper Scissors

----------------------------------------

"""

import random

import os

import re

os.system('cls' if os.name=='nt' else 'clear')

while (1 < 2):

print ("\n")

print ("Rock, Paper, Scissors - Shoot!")

userChoice = input("Choose your weapon [R]ock], [P]aper, or [S]cissors: ")

if not re.match("[SsRrPp]", userChoice):

print ("Please choose a letter:")

print ("[R]ock, [S]cissors or [P]aper.")

continue

# Echo the user's choice

print ("You chose: " + userChoice)

choices = ['R', 'P', 'S']

opponenetChoice = random.choice(choices)

print ("I chose: " + opponenetChoice)

if opponenetChoice == str.upper(userChoice):

print ("Tie! ")

#if opponenetChoice == str("R") and str.upper(userChoice) == "P"

elif opponenetChoice == 'R' and userChoice.upper() == 'S':

print ("Scissors beats rock, I win! ")

continue

elif opponenetChoice == 'S' and userChoice.upper() == 'P':

print ("Scissors beats paper! I win! ")

continue

elif opponenetChoice == 'P' and userChoice.upper() == 'R':

print ("Paper beat rock, I win!")

continue

else:

print ("You win!")