python初学者判断两个圆的位置关系


import math
#接收用户输入的两圆的圆心位置和半径
x1,y1= eval( input( "input the center of the first circle x,y:"))
r1= float( input( "input the radius of the first circle:"))
x2,y2= eval( input( "input the center of the second circle:x,y:"))
r2= float( input( "input the radius of the second circle:"))

d=math.hypot(x1-x2,y1-y2) #求圆心距

if d< abs(r1-r2):
print( "两圆内切")
elif d== abs(r1-r2):
if r1==r2:
print( "两圆重合")
else:
print( "两圆内切")

elif d
print( "两圆相交")
elif d==r1+r2:
print( "两圆外切")
else:
print( "两圆外离")



以下是hypot()方法的语法:



hypot(x, y)

注意:此函数是无法直接访问的,所以我们需要导入math模块,然后需要用math的静态对象来调用这个函数
参数

  •     x -- 这必须是一个数值
  •     y -- 此方法返回欧几里德范数 sqrt(x*x + y*y)

返回值

此方法返回欧几里德范数 sqrt(x*x + y*y)





你可能感兴趣的:(python,vscode)