Subscribe
提醒
guest

3 评论
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
虫虫Lynn
虫虫Lynn
5 年 之前

dist=input(‘please input distance:’) #输入一个距离
f=open(‘xy.dat’,’r’) #打开文件,文件为f
lines=f.readlines() #对文件f进行按行读取,保存在lines
for line in lines: #按行遍历lines
name=line.split(‘,’)[0] #分离点名
x=line.split(‘,’)[1] #分离x
y=line.split(‘,’)[2] #分离y
print (‘Point name:%s’ %name) #打印点名
print (‘x:%s’ %x)
print (‘y:%s’ %y)
xy=((float(x)-116.404)**2+(float(y)-39.914)**2)**0.5 #计算距离…
if xy>float(dist): #判断并输出信息
print (‘point %s within distance’ %name)
elif xy==float(dist):
print(‘point %s equal to distance’ %name)
else:
print(‘point %s without distance’ %name)
# end the file

虫虫Lynn
虫虫Lynn
Reply to  虫虫Lynn
5 年 之前

文档:跟着tom老师学习记录
链接:http://note.youdao.com/noteshare?id=1d8b72b182c31d64c98d14ba718d30ae&sub=2C002B31EE1C4F70B208C541A33F370A

虫虫Lynn
虫虫Lynn
5 年 之前

文档:跟着tom老师学习记录
链接:http://note.youdao.com/noteshare?id=1d8b72b182c31d64c98d14ba718d30ae&sub=2C002B31EE1C4F70B208C541A33F370A

3
0
交流思想,留下评论.x