我的拆分功能不起作用
My split function is not working
它给我 eof 解析错误。我不知道如何修复该拆分功能。请帮忙。谢谢。
#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()
提示你输入一个三元组但你按'Enter'时才会出现在一个完全空白的行上(空格除外)。
您可以使用以下方法处理该错误情况:
try:
a,b,c = input("Enter three measures of a triangle: ")
else:
raise RuntimeError("expected you to type three numbers separated by whitespace")
(使用 try...catch
并假设输入解析代码有效 ("EAFP: Easier to Ask Forgiveness than Permission") 更 Pythonic 和清洁,比在尝试拆分之前和之后添加额外的行来测试输入,这被视为 "Look before you leap" 代码。)
它给我 eof 解析错误。我不知道如何修复该拆分功能。请帮忙。谢谢。
#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()
提示你输入一个三元组但你按'Enter'时才会出现在一个完全空白的行上(空格除外)。
您可以使用以下方法处理该错误情况:
try:
a,b,c = input("Enter three measures of a triangle: ")
else:
raise RuntimeError("expected you to type three numbers separated by whitespace")
(使用 try...catch
并假设输入解析代码有效 ("EAFP: Easier to Ask Forgiveness than Permission") 更 Pythonic 和清洁,比在尝试拆分之前和之后添加额外的行来测试输入,这被视为 "Look before you leap" 代码。)