标签:import NPU style 猜数字 tin code 使用 游戏 port
1 import random 2 3 4 def print_game(): 5 print("-" * 30) 6 print("step1 欢迎界面---") 7 print("-" * 5, "欢迎使用AI牌游戏机", "-" * 5) 8 print("-" * 5, "1.猜数游戏", "-" * 5) 9 print("-" * 5, "2.猜拳游戏", "-" * 5) 10 print("-" * 5, "3.退出", "-" * 10) 11 print("-" * 30) 12 13 14 def shu_zi(): 15 print("猜数字游戏开始___") 16 while True: 17 num_1 = random.randint(1, 100) 18 i = 1 19 j = 1 20 while True: 21 num_2 = int(input("请输入一个整数(1-100)")) 22 if num_2 > num_1: 23 print("猜的第%d次,输入的数字大了" % i) 24 i += 1 25 elif num_2 < num_1: 26 print("猜的第%d次,输入的数字小了" % j) 27 j += 1 28 if num_2 == num_1: 29 print("恭喜你,猜对了,一共猜了%d次" % (i + j)) 30 break 31 get_1 = input("还要继续吗(y/n)") 32 if get_1 == "Y" or get_1 == "y": 33 continue 34 else: 35 break 36 37 38 def cai_quan(): 39 print("猜拳游戏开始___") 40 while True: 41 c_1 = random.randint(0, 2) 42 c_2 = int(input("请出拳(0:拳头1:布2:剪刀)")) 43 if (c_2 == 0 and c_1 == 2) or (c_2 == 1 and c_1 == 0) or (c_2 == 2 and c_1 == 1): 44 print("电脑出的是%d,你出的是%d,你赢了" % (c_1, c_2)) 45 elif c_1 == c_2: 46 print("平局") 47 get_2 = input("是否要继续猜拳游戏(y/n)") 48 if get_2 == "Y" or get_2 == "y": 49 continue 50 else: 51 break 52 else: 53 print("你输了,计算机出的是%d,你出的是%d" % (c_1, c_2)) 54 55 56 57 while True: 58 print_game() 59 choice = int(input("请选择要玩的游戏")) 60 if choice == 1: 61 shu_zi() 62 elif choice == 2: 63 cai_quan() 64 elif choice == 3: 65 get = input("真的要退出吗(y/n)") 66 if get == "Y" or get == "y": 67 break 68 else: 69 print("请选择要玩的游戏")
标签:import NPU style 猜数字 tin code 使用 游戏 port
原文地址:https://www.cnblogs.com/zh1127487137/p/12552955.html