Aug-11-2020, 09:05 AM
I am teaching myself python and have this function in a programme:
x1 = 1 x2 = 2 y1 = 4 y2 = 6 def distance(x1, y1, x2, y2): dx = x2 - x1 dy = y2 - y1 return 0.0 print(dx, dy)the output is:
Output:Python 3.8.4 (tags/v3.8.4:dfa645a, Jul 13 2020, 16:46:45) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
= RESTART: C:\Users\John\Documents\John''s files\Work\Coding\Think Like a Computer Scientist\Functions\distance_calculation.py
Traceback (most recent call last):
File "C:\Users\John\Documents\John''s files\Work\Coding\Think Like a Computer Scientist\Functions\distance_calculation.py", line 10, in <module>
print(dx, dy)
NameError: name 'dx' is not defined
>>>
I think I have defined dx at dx = x2 - x1 but clearly the Interpreter thinks not! Any help will be gratefully received