[Python] 用Python实现的"石头,剪刀,布" →→→→→进入此内容的聊天室

来自 , 2019-04-05, 写在 Python, 查看 153 次.
URL http://www.code666.cn/view/70821a40
  1. '''
  2. demonstrate Stone, Stainless, Paper game
  3. Created on 2012-11-1
  4.  
  5. @author: Eric
  6. '''
  7. import random;
  8.                           #elementA-->DRAW  WIN      LOST  
  9. COMPETE_RESULT = {"Stone":["Stone", "Stainless", "Paper"],
  10.                                 "Stainless":["Stainless", "Paper", "Stone"],
  11.                                 "Paper":["Paper", "Stone", "Stainless"]};
  12. SIGN = {0:"Stone", 1:"Stainless", 2:"Paper"}
  13. RESULTS = {0:"DRAW", 1:"WIN", 2:"LOST"};
  14.  
  15. def rochambeauGame():
  16.     print('''0:STONE
  17. 1:STAINLESS
  18. 2:Paper
  19. 3:quit
  20. ''');
  21.     while True:
  22.         userSign = input("please input your userSign number:");
  23.         if int(userSign) in (1, 2, 3, 0):
  24.             if userSign == 0:
  25.                 exit();
  26.             else:
  27.                 userSignResults = COMPETE_RESULT[SIGN[int(userSign)]];
  28.                 pcSign = SIGN[int(genereteRandomPCSign())];
  29.                 print("User Sign:" + SIGN[int(userSign)] + " PC Sign:" + pcSign + " \n####result is: user " + RESULTS[userSignResults.index(pcSign)]);
  30.         else:
  31.             print("please input correctly order");
  32. #generate a random number,[0,2]
  33. def genereteRandomPCSign():
  34.     return random.randrange(3);
  35.  
  36. if __name__ == '__main__':
  37.     rochambeauGame();
  38. #//python/5618

回复 "用Python实现的"石头,剪刀,布""

这儿你可以回复上面这条便签

captcha