1. 程式人生 > 其它 >python 用while迴圈實現猜年齡

python 用while迴圈實現猜年齡

number = 0
while True:
    number += 1
    age = 30
    input_age = int(input('請輸入你猜的年齡:'))
    if 150 >= input_age >0:
        if input_age == age:
            print('恭喜你,猜對了!')
            break
        else:
            print('不對,請重新猜!')
            if number < 3:
                continue
            else:
                input2 = input('你已經猜錯三次了,請問還需要猜麼?y or n>>>>')
                if input2 == 'y':
                    number = 0
                elif input2 == 'n':
                    exit('byebye')
    else:
        print('輸入錯誤,請重新輸入')
#缺少一個異常處理

  

作者:龍飛 出處:http://www.cnblogs.com/longfei825/

-------------------------------------------

個性簽名:獨學而無友,則孤陋而寡聞。做一個靈魂有趣的人!

如果覺得這篇文章對你有小小的幫助的話,記得在右下角點個“推薦”哦,博主在此感謝!