CateDoge
CateDoge

Reputation: 55

My split function is not working

It's giving me eof parsing error. I don't know how to fix that split function. Please help. Thank you.

#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.""")

Upvotes: 0

Views: 151

Answers (1)

smci
smci

Reputation: 33940

The error occurs in Python 2 (you should have said which version), and it only occurs when the input() prompts you for a triplet of numbers but you press 'Enter' on a totally blank line (other than whitespace).

You can handle that error condition with:

try:
    a,b,c = input("Enter three measures of a triangle: ")
else:
    raise RuntimeError("expected you to type three numbers separated by whitespace")

(It's more Pythonic and cleaner to use try...catch and assume the input-parsing code works ("EAFP: Easier to Ask Forgiveness than Permission"), than to add extra lines to test the input before and after you try to split it, which is looked down on as "Look before you leap" code.)

Upvotes: 1

Related Questions