I have written an article based on JS Stone scissors Cloth Program "JavaScript to achieve the stone scissors cloth game source sharing", today and based on Python wrote an example, where the edge of the algorithm is a little special but a moment also unexpected a good algorithm law.
Code:
Copy Code code as follows:
# Encoding=utf-8
# Stone Scissors Cloth Program
# under combined loadings
Import Random
# define a Dictionary of stone-scissors-cloth
Dict = {1: ' Scissors ', 2: ' Stone ', 3: ' Cloth '}
For row in Dict:
print ' number: ', row, ' = ', Dict[row]
print ' What are you out of? ' '
loop = True
While loop:
you = Raw_input (' Enter number return: ')
Try
you = Int (for you)
If You>=1 and you<=3:
loop = False
Else
print ' Please enter the number in the 1-3 range '
Except Exception,e:
print ' Please enter the correct number '
DN = Random.randint (1,3)
print ' You out: ', dict[you]
print ' Computer out: ', DICT[DN]
print ' Result: ',
If dn==you:
print ' Draw '
Elif (YOU>DN and You-dn==1) or YOU+2==DN:
print ' You win '
Else
print ' computer wins '