好的,我得到了下面的问题:给定一个整数列表,L,编写代码来确定列表中正整数的和是否 大于列表中负数之和的(绝对值)并打印适当的 留言。在
这是我为代码设计的,但它不起作用,它只是返回括号内的输入数字,例如input=-1,-2,4,5 output=(-1,-2,4,5)
def question(L):
L = input()
sumPositive = () #List where I will send the positive integers from "L" list
sumNegative = () #List where I will send the negative integers from "L" list
if x in L >= 0:
append.x(sumPositive) #checks if the number is equal to or greater than 0, if so add it to "sumPositive" list
elif:
append.x(sumNegative) #if not add it to "sumNegative" list
if sum(sumPositive) > abs(sum(sumNegative)):
print "The sum of positive numbers is greater than the absolute value of negative numbers."
elif:
sum(Positive) < abs(sum(sumNegative)):
print "The sum of absolute value of negative numbers is greater than the sum of positive numbers."
else:
print "They are equal."
有谁能告诉我我哪里出错了吗?或者我是不是做错了什么。谢谢!在
()
创建空元组,而不是列表。append()
是一种列表方法,例如foo.append(bar)
。在更像Python的解决方案:
相关问题 更多 >
编程相关推荐