-1

Getting a NameError of "add" not found:

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()
AlG
  • 14,697
  • 4
  • 41
  • 54
  • 1
    https://stackoverflow.com/questions/291978/short-description-of-the-scoping-rules?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa may help – AlG Mar 26 '18 at 19:36
  • 1
    You don't have any variable `add` defined in `main()`. What do you think it should print? – kindall Mar 26 '18 at 19:37
  • Where are you even calling `sumEach`? – chepner Mar 26 '18 at 19:37
  • 1
    Well, there's no variable named "add" in your `main` function, so what did you expect to happen? – Aran-Fey Mar 26 '18 at 19:38

1 Answers1

3

You have to call sumList and sumEach, not just use the name they would use to return a value if you had called them.

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

Each call needs to be passed a list of numbers to work with, which would appear to be the cause of the error you mention in the title.

chepner
  • 497,756
  • 71
  • 530
  • 681