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

Implemented Rock Paper Scissors #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions removeduplicates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def removeDuplicates(arr):
# Convert list to a set data structure where duplicates are not allowed.
# Sort the set according to original indices so that you don't lose order.
return sorted(set(arr), key=lambda x: arr.index(x))
26 changes: 26 additions & 0 deletions rockpaperscissors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Michael Nyamande 2016
import getpass #library to hide the user's input
moves = {"rock":1 ,"paper":2,"scissors":3}
def play(player):
move = getpass.getpass("{}'s move: ".format(player))
if move in moves:
return moves[move] #return numeric value of move
print("Invalid Move")
play(player) #Recursion

def compare(player1 ,player2):
diff = player1 - player2
if((diff%2==0 and diff<0) or (diff%2==1 and diff>0)):
return True # Player 1 won
else:
return False # Player 2 won

while input("Wanna Play ? ").lower() in ["y","yes"]:
player1 = play("player1")
player2 = play("player2")
if (player1==player2):
print("\nDraw \n")
else:
winner = "Player 1" if (compare(player1 ,player2)) else "Player 2"
print(" \n{} won the game \n".format(winner))
print("Thank you for playing")