我希望你能再次帮助我,我还不懂编程,所以请你忍受我。我有个错误:
Traceback (most recent call last):
File "C:\Python27\cx_Freeze exe Creator\Postcodezoekernl.py", line 136, in <module>
postcodeinvoer = int(postcodeinvoer)
TypeError: int() argument must be a string or a number, not 'NoneType'
程序可以运行,但是当我编译它时,当你关闭程序时,它会给出一个错误,说代码有问题。我试过删除这行,但是没有它程序就不能工作,因为它会直接转到ELSE语句。邮政编码1是特定数字之间的范围。用户必须填写一个数字。如果数字在该范围内,它将显示msgbox。你知道吗
elif keuze in week2:
postcodeinvoer = easygui.enterbox(msg="Voer een postcode in:", title="Postcodezoeker")
postcodeinvoer = int(postcodeinvoer)
if postcodeinvoer in postcode1:
easygui.msgbox(msg="[Woensdag 3 mei, 10 mei, 17 mei, 24 mei] [Donderdag 4 mei, 11 mei, 18 mei]", title=postcodeinvoer)
elif postcodeinvoer in postcode2:
easygui.msgbox(msg="[Dinsdag 2 mei, 9 mei, 16 mei, 23 mei] [Donderdag 4 mei, 11 mei, 18 mei]", title=postcodeinvoer)
elif postcodeinvoer in postcode3:
easygui.msgbox(msg="[Dinsdag 2 mei, 9 mei, 16 mei, 23 mei] [Donderdag 4 mei, 11 mei, 18 mei]", title=postcodeinvoer)
顺便问一下,有没有可能把一个python文件编译成一个.exe文件? 希望你们能帮我。提前谢谢!你知道吗
问题解决了!你知道吗
int(something)
将引发TypeError
或ValueError
,如果它可以从其参数实例化int,那么最简单的解决方案是捕获异常并重试。但是,由于我们希望允许用户取消操作,因此我们仍将测试None
,然后退出现在你似乎犯了一个新手常犯的错误,那就是认为如果某个东西是由数字组成的,那么它就是一个数字,事实并非如此。邮政编码或电话号码通常是字符串,而不是整数——问问自己,将电话号码乘以2,然后将结果除以邮政编码会有什么意义;)
你不应该把
postcodeinvoer
转换成int
。如果您所在国家的邮政编码仅由数字组成(并非所有国家都是这样),则可以测试用户输入是否是由N
数字组成的字符串(N
的值取决于您所在的国家):但即便如此,这也可能不是一个很好的验证。。。你知道吗
Check
postcodeinvoer
不是无。你知道吗相关问题 更多 >
编程相关推荐