|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import math
class Point():
def __init__(self):
a1=[]
a2=[]
self.a1=a1.append(input('请输入点A1的坐标:例如2,3'))
self.a2=a2.append(input('请输入点A2的坐标:'))
class Line(Point):
def __init__(self):
Point.__init__(self)
def getlen(self):
self.length=math.sqrt((self.a1[0]-self.a2[0])**2+(self.a1[1]-self.a2[1])**2)
return self.length
l=Line()
l.getlen()
报错
Traceback (most recent call last):
File "E:\python\My program\newq.py", line 20, in <module>
l.getlen()
File "E:\python\My program\newq.py", line 15, in getlen
self.length=math.sqrt((self.a1[0]-self.a2[0])**2+(self.a1[1]-self.a2[1])**2)
TypeError: 'NoneType' object is not subscriptable
思考以后看答案哦[
你程序的思路错误
输入的是形如a,b的字符串存入到了列表中,所以你读取a,b数据的过程是错误的
例如
若要获得1,则需要
提示至此,自己思考哦~
|
|