1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | # 剪刀石头布 import random a = ["Stone", "Scissors", "Paper"] ac = "" win = "You won" tie = "Tie" false = "Defeated" count = 0 win_count = 0 while True: ac = input("<<<") b = random.choice(a) print("{}".format(b)) count += 1 #判定输入是否有误 if ac != "Stone" and ac != "Scissors" and ac != "Paper" and ac !="exit": print("{}".format("""Please enter"Stone", "Scissors" or "Paper". """)) count -=1 continue #退出 if ac == "exit": print("""You've played {} time(s),odd is{:02}%""".format(count, average)) break if ac == "Scissors": if ac == b: print("{}".format(tie)) elif b == "Stone": print("{}".format(false)) else: print("{}".format(win)) win_count += 1 if ac == "Stone": if ac == b: print("{}".format(tie)) elif b == "Paper": print("{}".format(false)) else: print("{}".format(win)) win_count += 1 if ac == "Paper": if ac == b: print("{}".format(tie)) elif b == "Scissors": print("{}".format(false)) else: print("{}".format(win)) win_count += 1 #胜率计算 average = (win_count / count) * 100 print("""You've played {} time(s),odd is{:02}%""".format(count, average)) |