0%

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 59 60 61 62 63 64 65 66 67 68 69
| import random input("游戏规则:输入1代表出<拳头> 输入2代表出<剪刀> 输入3代表出<布>" "\n 按回车继续......") input("胜负关系为:1>2 2>3 3>1\n按回车开始游戏......") print("----------------------------------------------------------------------") number = int(input("请输入比赛回合:")) i = 1 win = 0 lose = 0 noun = 0 while i <= number: user = input("请输入需要出的拳:石头(1)/剪刀(2)/布(3):") user = eval(user) computer = random.randint(1, 300) h = number - i if user == 1: print(" 你出石头:%d" % user) elif user == 2: print(" 你出剪刀:%d" % user) else: print(" 你出布: %d" % user) if (computer >= 1) and computer <= 100: print("电脑出石头:1 --(%d)" % computer) elif (computer > 100) and computer <= 200: print("电脑出剪刀:2 --(%d)" % computer) else: print(" 电脑出布:3 --(%d)" % computer) if (user == 1 and ((computer >= 1) and computer <= 100)) or ( user == 2 and ((computer > 100) and computer <= 200)) or ( user == 3 and ((computer > 200) and computer <= 300)): noun = 1 print("本回合平局!无胜负关系,重新再来!") elif user == 1 and (computer > 100) and computer <= 200 or user == 2 and ( computer > 200) and computer <= 300 or user == 3 and (computer >= 1) and computer <= 100: noun = 0 win += 1 if h == 0: print(f"本回合你赢了!回合结束,正在计算胜负关系......") else: if win == int(number / 2 + 1): print("本回合你赢了!回合结束,正在计算胜负关系......") else: print(f"本回合你赢了!但别太高兴,你只赢了{win}个回合-----------------------还剩{h}个回合!") if win == int(number / 2 + 1): print("----------------------------------------------------------------------") print(f"好吧,你赢了,{number}局游戏赢了{win}局!") print("恭喜你!成功赢了电脑!牛牛牛牛牛牛牛牛牛牛牛牛牛牛牛牛牛牛牛牛牛牛牛牛牛牛牛牛!") break else: noun = 0 lose += 1 if h == 0: print("本回合你输了!回合结束,正在计算胜负关系......") else: print(f"本回合你输了!菜狗,电脑都赢不了,你已经输了{lose}回合了-----------------------还剩{h}个回合") print("----------------------------------------------------------------------") if lose == int(number / 2 + 1): print("很遗憾,你输了!") print(f"{number}个回合你已经输了{lose}个回合了,我奶奶玩都比你强!") break elif (i == number) and win == number / 2: print(f"{number}个回合你只赢了{win}个回合:平局!") if noun == 1: i = i else: i += 1
|