它给了我分析错误的机会。我不知道如何修复那个分裂函数。请帮忙。非常感谢。你知道吗
#Is It An Equilateral Triangle?
def equiTri():
print("Enter three measure of a triangle: ")
a, b, c = input().split()
a = float(a)
b = float(b)
c = float(c)
if a == b == c:
print("You have an Equilateral Triangle.")
elif a != b != c:
print("This is a Scalene Triangle not an Equilateral Triangle.")
else:
print("""I'm guessing this is an Isosceles Triangle so definitely
not
an Equilateral Triangle.""")
这个错误发生在Python2中(您应该说明是哪个版本),并且只有当
input()
提示您输入三元组数字,但您在完全空白的行(除了空格)上按“回车”时才会发生。你知道吗您可以使用以下方法处理该错误情况:
(使用
try...catch
并假设输入解析代码可以工作(EAFP:请求原谅比请求许可更容易),比在尝试拆分输入前后添加额外的行来测试输入更具python性和简洁性,这被视为“三思而后行”代码。)相关问题 更多 >
编程相关推荐