Objective:
This script implements the game of scissors and stone cloth, but there is no exception handling. Only user input 0, 1, 2 o'clock can be normal processing.
#!/usr/bin/env python
# Coding:utf8
Import Random//Imports random module, which is a module that generates random numbers
All_choice = ["Stone", "scissors", "cloth"]//define a list and add the selection to the list
Win_list = [["Stone", "Scissors"],["scissors", "cloth"],["cloth", "stone"]]//Define a user-won list, the elements in the list are still a list
prompt = "" "(0) stone//define a variable and write the prompt to this variable
(1) Scissors
(2) Cloth
Please select (0/1/2): "" "
IND = Int (raw_input (prompt))//Because a string type is entered, the string is converted to an integer type
Player = All_choice[ind]//list can be removed from the list of values in the corresponding index
Computer = Random.choice (all_choice)//random selection of a value
Print "Your choice:%s, Computer choice:%s"% (player, computer)//prompt information, friendly interface
If player = = computer://If the values of these two variables are equal
Print "\033[32;43;1m draw \033[0m"//Output Draw
elif [player, computer] in Win_list://If the list is in Win_list
print "\033[31;45;1myou Win!!! \033[0m "//Output you won
ELSE://otherwise
print "\033[31;46;1myou lose!!! \033[0m "//Just out you lose
Note: \00[30+ is the foreground color, 40+ is the background color, \033 0m is turned off the colour end 1m is the aggravating display
This article is from the "Court of the Odd Tree" blog, please be sure to keep this source http://zhangdl.blog.51cto.com/11050780/1827486
Writing: Python Implements scissors, stone, cloth games