获取&#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()
答案 0 :(得分:3)
您必须致电sumList
和sumEach
,而不只是使用他们用 调用它们时返回值的名称。
print ("Sum of list: ", sumList(nums))
print ("List squared", sumEach(nums))
每个电话都需要传递一个要使用的号码列表,这似乎是你在标题中提到的错误的原因。