用Python实现的"石头,剪刀,布",Python实现,'''demonstra


'''demonstrate Stone, Stainless, Paper gameCreated on 2012-11-1@author: Eric'''import random;                          #elementA-->DRAW  WIN      LOST  COMPETE_RESULT = {"Stone":["Stone", "Stainless", "Paper"],                                "Stainless":["Stainless", "Paper", "Stone"],                                "Paper":["Paper", "Stone", "Stainless"]};SIGN = {0:"Stone", 1:"Stainless", 2:"Paper"}RESULTS = {0:"DRAW", 1:"WIN", 2:"LOST"};def rochambeauGame():    print('''0:STONE1:STAINLESS2:Paper3:quit''');    while True:        userSign = input("please input your userSign number:");        if int(userSign) in (1, 2, 3, 0):            if userSign == 0:                exit();            else:                userSignResults = COMPETE_RESULT[SIGN[int(userSign)]];                pcSign = SIGN[int(genereteRandomPCSign())];                print("User Sign:" + SIGN[int(userSign)] + " PC Sign:" + pcSign + " \n####result is: user " + RESULTS[userSignResults.index(pcSign)]);        else:            print("please input correctly order");#generate a random number,[0,2]def genereteRandomPCSign():    return random.randrange(3);if __name__ == '__main__':    rochambeauGame();

评论关闭