1. 程式人生 > >python 入門 guess 函數

python 入門 guess 函數

ESS AD == you too 使用 inpu bre SM

猜年齡限制次數,使用while函數和count計數器。

age_of_spencer = 28
count = 0
while True:
    if count == 2:
        break
    age = int(input("age:"))
    if age == age_of_spencer:
        print("you made it")
        break
    elif age >= age_of_spencer:
        print("too big")
    else:
        print("too small"
) count = count + 1 if count==2: print("you had tried too many times")

python 入門 guess 函數