from random import randint val = randint(0,9) inputVal = '' num = 0 while True: num += 1 inputVal = int(input('请输入一个整数(q退出):')) if inputVal > val: print('遗憾,太大了') elif inputVal< val: print('遗憾,太小了') else: print(f'预测{num}次,你猜中了') break