-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)

7
  • you have not posted all the code (that error can't have come from this snippet!) Commented Apr 20, 2019 at 19:23
  • Unless "name" is actually r1 and you're paraphrasing. Post the actual error. Commented Apr 20, 2019 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. Commented Apr 20, 2019 at 19:29
  • What's the traceback? Commented Apr 20, 2019 at 19:31
  • always put full error message (Traceback) in question (as text, not screenshot). There are other useful information. Commented Apr 20, 2019 at 19:35

1 Answer 1

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`
Sign up to request clarification or add additional context in comments.

1 Comment

Um, no. Functions can access values not fed as arguments to it

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.