class建立问题求助
建立Point(点)的类,截取了相关部分。import random as r
class Point:
def __init__(self):
self.a_x = r.randint(0,10)
self.a_y = r.randint(0,10)
self.b_x = r.randint(0,10)
self.b_y = r.randint(0,10)
print('A :',self.a_x,' ',self.a_y)
print('B :',self.b_x,' ',self.b_y)
运行后出现以下错误:
Traceback (most recent call last):
File "F:/Programming/Python/practice/38.1.py", line 3, in <module>
class Point:
File "F:/Programming/Python/practice/38.1.py", line 9, in Point
print('A :',self.a_x,' ',self.a_y)
NameError: name 'self' is not defined
求大佬指导! 把最后两行的缩进右移与上面相同。
缩进错了... print 函数那两行需要加个缩进
页:
[1]