Python-implemented stone-scissors-cloth code sharing _python

Source: Internet
Author: User

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&GT;DN and You-dn==1) or YOU+2==DN:
print ' You win '
Else
print ' computer wins '

Related Article

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.