"Everything is related to everything else, but near things are more related than distant things"
Rock Paper Scissor
The Python function simulates two computer player’s Rock Paper Scissor game: the function will have one argument supply as how many games to play. Then the function will print results about each player’s win and lose and return draw game percentage out of the total.
# Ehsan Momeni
from random import *
print "Rock, Paper, Scissor!!\n\n"
def RPG(number_iteration): #function defined
game=[] # game states
for i in range(1,number_iteration+1): # iterates
list=['R', 'P', 'S']
computer1=list.pop(randint(0,len(list)-1)) #for computer 1
list=['R', 'P', 'S']
computer2=list.pop(randint(0,len(list)-1)) #for computer 2
if (computer1, computer2) in [("R","S"),("S","P"),("P","R")]: # computer1 win
game.append("computer1")
elif (computer1, computer2) in [("R","P"),("S","R"),("P","S")]: # computer2 win
game.append("computer2")
else: # draw
game.append("Draw")
print "Computer1 won %d times,\nComputer2 won %d times,\nDraw happened %d times"%(game.count("computer1"), game.count("computer2"), game.count("Draw"))
percentage=game.count("Draw")*100/int(number_iteration) #percent of draw
print "\n\nDraw happened %.2f percent"%(percentage)
return percentage
RPG(1000)