不明白为什么一直给我一个错误

时间:2019-03-22 17:43:54

标签: python try-except

我不断收到此错误:

ERROR: Got an exception. Message: Traceback (most recent call last): File "<string>", line 7, in shuffle File "<string>", line 7, in shuffle Exception: ERROR:action is out of range

有人可以帮我吗!

2 个答案:

答案 0 :(得分:1)

我相信您的代码中的问题如下:

操作时:

int(action)

如果无法将值转换为int,则会引发ValueError。但这不会将行动变成一体。

您需要保存转换后的值:

action = int(action)

祝你有美好的一天,

G

答案 1 :(得分:0)

在该range部分添加if action...,然后重试,您将其写入了列表。这样...

if action not in (range(1,3)):

另外,以防万一,出于冗余的原因,在您的操作之前放置int(,就好像它被视为字符串一样,它不适用于范围。

相关问题