用while循環寫猜年齡以及優化版
阿新 • • 發佈:2018-07-05
pre color 輸出 lse elif 年齡 break too while
增加:1、循環猜,2、最多猜3次,3、超過3次輸出猜次數過多:
age_of_XueKe=18
count=0
while True:
if count==3:
break
age = int(input("age:"))
if age == age_of_XueKe:
print("Yes,you got it!")
break
elif age >age_of_XueKe:
print("Think smaller!")
else:
print("Think bigger!")
count=count+1
if count==3:
print("You have tried too many times...")
優化版:
age_of_XueKe=18
count=0
while count<3:
age = int(input("age:"))
if age == age_of_XueKe:
print("Yes,you got it!")
break
elif age >age_of_XueKe:
print("Think smaller!")
else:
print("Think bigger!")
count=count+1
else:
print("You have tried too many times...")
用while循環寫猜年齡以及優化版