1. 程式人生 > >python while循環

python while循環

inpu pri 機會 break light div == ans count

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(‘機會用完了‘)

  

python while循環