This article mainly introduces the Python-implemented stone scissors cloth code sharing. this article and another JavaScript-implemented stone scissors cloth game source code is sister-in-law, for more information, see the JavaScript-based Stone scissors game source code sharing. I wrote an example based on Python, the algorithm here is a bit special, but I cannot think of a good algorithm law at the moment.
Code:
The code is as follows:
# Encoding = UTF-8
# Stone scissors program
# Li Zhong
Import random
# Define the stone scissors Dictionary
Dict = {1: 'scissors ', 2: 'stone', 3: 'cloth '}
For row in dict:
Print 'number: ', row,' = ', dict [row]
Print 'what do you get? '
Loop = True
While loop:
You = raw_input ('Enter the number and press enter :')
Try:
You = int (you)
If you> = 1 and you <= 3:
Loop = False
Else:
Print 'Enter the number in the range of 1-3'
Except t Exception, e:
Print 'Enter the correct digit number'
Dn = random. randint (1, 3)
Print 'out: ', dict [you]
Print 'computer output: ', dict [dn]
Print 'result :',
If dn = you:
Print 'draw'
Elif (you> dn and you-dn = 1) or you + 2 = dn:
Print 'win out'
Else:
Print 'computer wins'