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!