I was writing code and came across a certain anomaly in my opinion. I created a primer that reproduces this error.
num2 = 1234
num1 = 123
class.class1():
def function1(num1, num2):
t = num1 + num2
return t
def function2(num1, num2):
print(function1(num1, num2))
class1.function2(num1, num2)
console
Traceback (most recent call last): File "/home/runner/Python/main.py", line 12, in roro.function2(num1, num2) File "/home/runner/Python/main.py", line 9, in function2 print(function1(num1, num2)) NameError: name 'function1' is not defined
I didn’t find the answer on the Internet and asked the AI in "replit" to solve this problem, but it gave me a “corrected code” that was identical to mine. In general, I'm at a dead end. Please help. Tell me what am I doing wrong?
I added self to every function but it didn't work.
and I did this: "The object the function is called on automatically gets passed as self.
So if you call x.add(y), self will be x and other will be y"
class
Traceback (most recent call last): File "/home/runner/Python/main.py", line 11, in class1.num1.function2(num2) AttributeError: type object 'class1' has no attribute 'num1'
Traceback (most recent call last): File "/home/runner/Python/main.py", line 11, in class1.function2(num1, num2) TypeError: class1.function2() missing 1 required positional argument: 'num2'
Traceback (most recent call last): File "/home/runner/Python/main.py", line 11, in class1.function2(num1, num2) TypeError: class1.function2() missing 1 required positional argument: 'num2'