Python applets: scissors, stones, and cloth instance code

Source: Internet
Author: User
This article mainly introduces python applets: scissors, stones, and instance code. it has some reference value, interested friends can refer to this article for details about the python applet: scissors, stones, and instance code, which has a certain reference value, for more information, see

Nothing to worry about. write a small program and practice python. haha:

#! /Usr/bin/env python

# Coding: utf8

# Author: wangganyu188@163.com

# Date: 2014-09-11

Import random, sys

# Define the stone scissors Dictionary

Dict = {

1: 'scissors ',

2: 'stone ',

3: 'bus ',

}

For row in dict:

Print 'number: ', row,' = ', dict [row]

Loop = True

While loop:

Print 'what do you get? '

You = raw_input ('Enter the number and press the Enter key if you want to exit the game. '). strip ()

If you = 'Q ':

Loop = False

Print "friendly reminder: The game will quit and you will be playing again next time"

Sys. exit ()

Else:

Try:

Dn = random. randint (1, 3)

You = int (you)

If you> = 1 and you <= 3:

Loop = True

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'

Continue

The above is the details of the python applet: scissors, stones, and cloth instance code. For more information, see other related articles in the first PHP community!

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.