我在 python 中編碼,我想知道是否有辦法更改輸入的數(shù)據(jù)類型。我設(shè)計了一個代碼來表示我的問題: menu= input("test>>> ") if (menu)==("forprint"): fortimes= input ("range>>>>") forprintwhat= input ("print>>>>>") for x in range (fortimes): print (forprintwhat)現(xiàn)在很明顯,我得到了這個錯誤:Traceback (most recent call last):File "C:/Users/vas71/AppData/Local/Programs/Python/Python38/leaf.py", line 15, in <module>for x in range (fortimes):TypeError: 'str' object cannot be interpreted as an integer注意:錯誤消息顯示“第 15 行”,因為我是從較大的文本中復(fù)制它。我的問題是,如何使字符串成為整數(shù)以便我的代碼工作?是否可以?感謝您的幫助!
有沒有辦法更改輸入數(shù)據(jù)類型?
慕無忌1623718
2023-03-08 15:16:57