Reputation: 105
I am making a program that determines if a triangle is obtuse(O),acute(A) or right(R)
Enter in the length of angles
>>> 3 8 9
TypeError: pythag() takes exactly 3 arguments (1 given)
I understand why I'm getting the error but what I'm trying to do is somehow loop the values of the list into the function and then call the function.
input = raw_input("Enter in the length of angles\n>>> ") #>>> 3 8 9
lst = input.split() #splits the input into a list by whitespace
for i in lst: #converts the values in the list to integers
int(i)
def pythag(a,b,c): #function to perform calculation
if a^2 + b^2 != c^2:
if c^2 > a^2 or b^2:
return "A"
else:
return "O"
else:
return "R"
pythag(lst)
Any suggestions?
Thanks in advance.
Upvotes: 0
Views: 61
Reputation: 34282
First of all, int(i)
does nothing to the original list, so it still contains strings. Second, which is where your exception happens, is that you are still passing a single argument to the function.
lst = [int(i) for i in lst] # convert the input
pythag(*lst) # same as pythag(lst[0], lst[1], ...)
Upvotes: 3