zl程序教程

您现在的位置是:首页 >  后端

当前栏目

python while循环

Python循环 while
2023-09-27 14:22:23 时间
count = 0
answer = 10

while True:
    print(count)
    count += 1
    guess = int(input('猜一个'))
    if guess == answer:
        print('ok')
        break
    elif guess > answer:
        print('猜大了')
    else:
        print('猜小了')

    if count ==10:
        break
print('第二个while')
count = 0
while count <3:
    count +=1
    guess = int(input('猜一个'))
    if guess == answer:
        print('ok')
        break
    elif guess < answer:
        print('猜小了')
    else:
        print('猜大了')
else:
    print('机会用完了')