-------------------------------代码部分如下-----------------------------------
import math
import re
def inputdata(i) :
# 输入第一个坐标点a
x1, y1 = input("请输入第{}坐标点的x值和y值,以空格隔开:".format(i)).split()
# 正则表达式判断是否为小数,若不为小数,则给出提示,重新输入
float_data = re.compile(r'^[-+]?[0-9]+\.?[0-9]*$')
x = float_data.match(x1)
y = float_data.match(y1)
# x,y坐标同时满足要求时返回值,否则重新输入
if x and y :
print(x1, y1)
print(type(x1),type(y1)) # 是string类型
return float(x1), float(y1) # string类型转换成浮点型
else :
print("输入错误,请输入整数或浮点数")
# return 0,0
inputdata(i)
# 获取第一个坐标点
ax, ay = inputdata(1)
# print(type(ax))
# 获取第二个坐标点
bx, by = inputdata(2)
# 获取第三个坐标点
cx, cy = inputdata(3)
# print(cx+cy)
# print(type(cx))
# 计算三条边长
a = math.sqrt(math.pow((ax - bx), 2) + math.pow((ay - by), 2))
b = math.sqrt(math.pow((bx - cx), 2) + math.pow((by - cy), 2))
c = math.sqrt(math.pow((ax - cx), 2) + math.pow((ay - cy), 2))
if a + b > c and a + c > b and b + c > a :
# 海伦公式
p = (a + b + c)
print('p:', p, a, b, c)
S = math.sqrt(p * (p - a) * (p - b) * (p - c))
print("三角形面积为:%.2f" % S)
else :
print("三角形不成立")
-----------------------------------------问题----------------------------------------
运算结果如下,为什么第二次输入错误的坐标,再按提示重新输入正确的坐标表后,返回值接受不到?
