while循环
1.设置终止条件
import random
random_num=random.randint(1,100)
print(random_num)
count=0
flag=True
while flag:
guess_num=int(input("请输入猜测的数字:"))
count+=1
if(random_num==guess_num):
print("猜对啦")
flag=False
else:
if(guess_num>random_num):
print("猜大了")
else:
print("猜小了")
print(f"一共猜测了{count}次")