TypeError:sumEach()缺少1个必需的位置参数:' nums'

时间:2018-03-26 19:34:40

标签: python

获取&#34的NameError;添加"找不到:

import math
import statistics

def main():

    numbers = str(input("Enter numbers separated by spaces: ")).split()
    nums = list(map(int, numbers))

    print ("Original List", nums)
    print ("Sum of list: ", add)
    print ("List squared", squared)

def sumEach(nums):
    squared = []
    for i in range (1, 6):
        squared.append(i ** 2)
    return squared

def sumList(nums):
    add = sum(nums)
    return add

main()

1 个答案:

答案 0 :(得分:3)

您必须致电sumListsumEach,而不只是使用他们用 调用它们时返回值的名称。

print ("Sum of list: ", sumList(nums))
print ("List squared", sumEach(nums))

每个电话都需要传递一个要使用的号码列表,这似乎是你在标题中提到的错误的原因。