这是我代码的基本版本。
它说我的“ h = abc(shotX,shotY)”语句有问题。这是检查函数返回值的正确方法吗?它一直说“未定义shotX名称”。
def abc(shotX,shotY)
x = abs(300 - shotX)
y = abs(300 - shotY)
if x < 150 and y < 150:
return True
else:
return False
def main():
h = abc(shotX,shotY)
if h:
print("h is", h)
else:
print("no")
答案 0 :(得分:0)
这是因为未定义,请尝试执行此操作。要使用变量,必须首先将其初始化为value,这可以像var = "foo"
def abc(shotX,shotY):
x = abs(300 - shotX)
y = abs(300 - shotY)
if x < 150 and y < 150:
return True
else:
return False
def main():
shotX = 0
shotY = 0
h = abc(shotX,shotY)
if h:
print("h is", h)
else:
print("no")
答案 1 :(得分:0)
您在这里犯了一些严重的错误。至于main函数,您有未声明的变量shotX,shotY(因为它们特别引起错误)。 它应为:-
create table #temp (id int, amount int)
insert into #temp values (1, 100)
insert into #temp values (2, -10)
insert into #temp values (3, 50)
insert into #temp values (4, -80)
insert into #temp values (5, 20)
insert into #temp values (6, -20)
with positive as
(select sum(amount) as posNum from temp where amount > 0)
, negative as
(select sum(amount) as negNum from temp where amount < 0)
select *, (select * from negative) from positive
此外,您还有缩进问题,并且在函数abc处缺少分号
def main():
shotX = #something
shotY = #something
h = abc(shotX,shotY)
if h:
print("h is", h)
else:
print("no")
现在您的代码应该可以正常工作了。
答案 2 :(得分:0)
答案1:
def abc(): <--
x = abs(300 - shotX)
y = abs(300 - shotY)
if x < 150 and y < 150:
return True
else:
return False
答案2:
def main(shotX,shotY):
h = abc(shotX,shotY)
if h:
print("h is", h)
else:
print("no")
答案3:
shotX = # any int
shotY = # any int
def abc(shotX,shotY):
x = abs(300 - shotX)
y = abs(300 - shotY)