本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
方法一:使用eval()函数,输入的持续为数字
definputInt(content='请输入整数:'): whileTrue: data=input(content) try: inputData=eval(data) iftype(inputData)==int: #break returninputData except: pass if__name__=="__main__": print(inputInt())
方法二、使用int()转换
whileTrue: ten=None try: ten=int(input("x:")) except: pass iftype(ten)==int: break
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)