#用户选择剪刀石头布,电脑随机生成,若是输了扣一分,赢了加一分,打平不加分。最后可以显示总分,可以无限循环,可以手动终止。 from random import randint # write in 20220707 score = 0 while True: hand = ("剪刀", "石头", "布") computer = randint(0, 2) choice = input("请选择\n" + "1:" + "\u270c " + "2:" + "\u270a " + "3:" + "\u270b\n") if choice not in ['1', '2', '3']: print("不是正确选择!退出!") exit() choice = int(choice) print("你的选择是:", hand[choice - 1], " 电脑的选择是:", hand[computer]) if choice-1 == computer: print("你们打平了!") score += 0 print("你的得分目前是:", score) elif choice-1-computer == 0 or choice-1-computer == 1 or choice-1-computer == -2: print("恭喜你获胜了!") score += 1 print("你目前得分是:", score) else: print("可惜,你输了~!") score = score - 1 print("你的目前得分是:", score) result = input("请问是否想继续?继续按“Y” 不想按“N”(支持大小写,其他字符按继续处理)\n") if str(result) == "n" or str(result) == "N": print("你最终的得分是:", score) break
python猜丁壳,可以计算总分。(石头剪刀布)
于 2022-07-15 10:41:21 首次发布