-1

Consider the following code:

def distancias(altitudes,lado,p1,p2):
    p1=(r1,c1)
    p2=(r2,c2)
    a1=altitudes[p1]
    a2=altitudes[p2]
    d=math.sqrt((lado(r1-r2)**2)+(lado(c1-c2)**2)+(a1-a2)**2)
    return d

Altitudes is a matrix and p1 and p2 are elements of the matrix.

When I call the function distancias(teste, 20, (2, 0), (3, 1)), it is giving me this error:

Traceback (most recent call last):

  File "<ipython-input-11-6c6a4bb1ff77>", line 1, in <module>
    distancias(teste, 20, (2, 0), (3, 1))

  File "C...", line 5, in distancias
    p1=(r1,c1)

NameError: name 'r1' is not defined

    "Name Error: name is not defined".

(I want to understand it better as i am new to Python)

Rory Daulton
  • 21,934
  • 6
  • 42
  • 50
Mpc
  • 1
  • 4
  • you have not posted all the code (that error can't have come from this snippet!) – Joe Iddon Apr 20 '19 at 19:23
  • Unless "name" is actually `r1` and you're paraphrasing. Post the actual error. – Carcigenicate Apr 20 '19 at 19:27
  • 1
    Welcome to StackOverflow. To help you with your error, you need to show us a complete code snippet that shows that error when we run that code. Please read and follow [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Rory Daulton Apr 20 '19 at 19:29
  • What's the traceback? – Alec Apr 20 '19 at 19:31
  • always put full error message (Traceback) in question (as text, not screenshot). There are other useful information. – furas Apr 20 '19 at 19:35
  • error `“Name Error: name is not defined”` means that variable `name` is not defined but you try to use variable `name` - ie. to get value from variable - `other = name`, `function(name)`, – furas Apr 20 '19 at 19:37
  • Did you mean `(r1, c1) = p1` and `(r2, c2) = p2`? In Python, you cannot reverse statements like this. Your code does not make much sense as is. – Artemis Apr 20 '19 at 22:14

1 Answers1

0

hello this is because "r1,c1,r2,c2" are not the definition of function distancias. so use should define these variable before using them. Actually you should post the full code for better understanding of others.but if you this piece to work.you should change something like this.

     `def distancias(altitudes,lado,r1,r2,c1,c2):
      p1=(r1,c1)
      p2=(r2,c2)
      a1=altitudes[p1]
      a2=altitudes[p2]
      d=math.sqrt((lado(r1-r2)**2)+(lado(c1-c2)**2)+(a1-a2)**2)
      return d`