【Python】try、expect異常的簡單案例,同While循環語句共同使用

while True:
    try:
        a = int(input("please input:"))
        print(a **2)
        break
    except:   # 當輸入浮點數、漢字、字母等就會拋出異常。
        print("sorry, please input again!")

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章