Python applet: Scissors, stone, cloth

Source: Internet
Author: User

Nothing to do, write a small program, practice python, haha:

 

#!/usr/bin/env python

#coding: UTF8

#author: [Email protected]

#date: 2014-09-11


Import Random,sys



#定义石头剪子布字典


Dict = {

1: ' Scissors ',

2: ' Stone ',

3: ' Cloth ',

}



For row in Dict:

print ' number: ', row, ' = ', Dict[row]


loop = True

While loop:

print ' What are you out of? '

you = Raw_input (' Please enter the number of carriage return: If you want to exit the game press the Q key '). Strip ()

If you = = ' Q ':

loop = False

Print "Friendly reminder: The game will exit, welcome to play next time"

Sys.exit ()

Else

Try

DN = Random.randint (1,3)

you = Int (you)

If you >= 1 and <= 3:

loop = True

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 '

Continue

    

This article from "Easier Avenue to Jane" blog, declined reprint!

Python applet: Scissors, stone, cloth

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.