報錯:TypeError: '>' not supported between instances of 'str' and 'int'

當我們編程時,有時會出現如下錯誤:TypeError: '>' not supported between instances of 'str' and 'int' 如下圖: 這是因爲input()返回的數據類型是str類型,不能直接和整數進行比較,必須先把str轉換成整型,使用int()方法:age = int(input ("請輸入你的年齡:")) 改正之後爲: 這樣程序就達到了預期的效果了
相關文章
相關標籤/搜索