【发布时间】:2017-06-09 14:24:32
【问题描述】:
我编写了这个简单的脚本来使用 Shadowrun 5E 规则进行可用性测试,该规则基于使用 Zapier 的 google 表单中的数据。但是,当我运行这个很酷时,Zapier 返回一个错误。一切似乎都井井有条,我做错了什么?
import random
itempoolgot = int(input_data.get('itempool'))
opposedpoolgot = int(input_data.get('opposedpool'))
itempoolloops = 0
itemhits = 0
opposedpoolloops = 0
opposedhits = 0
while (itempoolloops <= itempoolgot):
diceresult = random.randint(1, 6)
itempoolloops = itempoolloops + 1
if diceresult >=5:
itemhits = itemhits + 1
while (opposedpoolloops <= opposedpoolgot):
diceresult = random.randint(1, 6)
opposedpoolloops = opposedpoolloops + 1
if diceresult >=5:
opposedhits = opposedhits + 1
return {
'opposedhits': opposedhits, 'itemhits' : itemhits
}
这是错误消息“Bargle。我们在创建运行 python 时遇到错误。:-( 错误: 你的代码有错误!”
我运行了另一个代码,它只生成一个随机数并且它可以工作,它可能是 while 循环有问题。
编辑 2:通过跳过 Zapier 中的测试步骤,我发现此错误:发送到代码“运行 Python”失败:您的代码有错误! Traceback(最近一次调用最后一次):文件“/tmp/tmpQdoNPW/usercode.py”,第 16 行,在 the_function diceresult = random.randint(1, 6) NameError: global name 'random' is not defined
【问题讨论】:
-
"Zapier 返回一个错误" -> 我们对这个问题的了解与您在问题中所写的一样多。因此,我们无法读懂您的想法并“知道”错误是什么。请在您的帖子中包含确切的错误消息。
-
这就是我得到的“Bargle。我们在创建运行 python 时遇到错误。:-( 错误:您的代码有错误!”我认为 Zapier 可能不允许 while 循环,因为我运行一个没有while循环的代码,它运行良好。
-
Zapier 是出了名的不擅长编写错误消息。
-
您的输入数据是否可能没有这两个值?如果您将
None传递给int(),它将引发异常。 -
我在代码中发现了一个错字,但仍然出现错误。