Python-implemented stone scissors code sharing

Source: Internet
Author: User
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'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.