Python猜数字游戏 import random n = random.randint(1,101) cnt = 0 while True: ans = int(input(“请输入一个数字”)) cnt += 1 if ans == n: print(“猜对了,你一共猜了%d次” % cnt) break elif ans > n: print(“大了”) else: print(“小了”)