-3
def sum(a, b, c, d):
    result = 0
    result = result+a+b+c+d
    return result


def length():
    return 4


def mean(a, b, c, d):
    return float(sum(a, b, c, d))/length()


print(sum(a, b, c, d), length(), mean(a, b, c, d))

I am getting the error message name 'a' is not defined

greybeard
  • 2,249
  • 8
  • 30
  • 66
RAW CLUB
  • 5
  • 1

2 Answers2

1

If you don’t define the variable you’ll gonna get these name errors. Let’s say for example you switch the values when you call these functions -

print(sum(a, b, c, d), length(), mean(a, b, c, d))

Here, in this case you’ll gonna get name b is not defined because Python interpreter doesn’t know what’s the value that variable b is storing.

You need to tell the interpreter what are the values for these variables.

For example - a=10, b=2,.. and so on

Nk03
  • 14,699
  • 2
  • 8
  • 22
0

a variable is undefined means that you need to define (assign a value) to that variable. For example, a=1 should work.

Moaz Fathy
  • 91
  • 4