Python函数printng out all for all evens(1-10)但不是数字

时间:2016-06-29 00:59:31

标签: python-3.x

我做了一个python函数,它假设从1-100打印出偶数并添加总和。我设法打印出总和,但数字不打印出来。

def main():
    BuildList()

def BuildList():
    lstEvens = []
    for i in range(0,101):
        if i % 2 == 0:
            lstEvens.append(i)
    SumList(lstEvens)

def SumList(lstEvens):
    totalofEvens = sum(lstEvens)
    ShowResults(totalofEvens)

def ShowResults(totalofEvens):
    print("The sum of all Even numbers combined is" ,totalofEvens)
    print(lstEvens)

main()

1 个答案:

答案 0 :(得分:0)

lstEvens未在函数ShowResults中定义。