立即学习:https://edu.csdn.net/course/play/24459/296927?utm_source=blogtoedu
a = 0 while a < 5: a += 1 import random n = random.randint(0,10) sui_ji = int(input("请输入数字:")) if sui_ji > n or sui_ji < n: print("猜错了请重新输入") b = 0 while b < 5: b += 1 if a == 5: jixu1 = ("y") jixu2 = ("Y") ji_xu = input("是否继续?") if ji_xu == jixu1 or ji_xu == jixu2: c = 0 while c < 5: c += 1 sui_ji = int(input("请输入数字:")) if sui_ji > n or sui_ji < n: print("猜错了请重新输入") else: print("游戏结束") exit() elif sui_ji == n: print("恭喜猜对了") exit()
这是猜数字的作业,猜5次后没猜出来然后继续在猜5次。一共有5条命,5条命的意思就是有5次猜5次的机会!语音组织能力差大家试试代码就明白了!