Reputation: 73
So Im doing a little Right Triangle Checker
def RightTriangleChecker(Number1,Number2,Number3):
AllNumbers=[Number1,Number2,Number3]
Hypotonuse=max(AllNumbers)
if(Number1**2+Number2**2==Number3**2):
print "This is a right triangle."
else:
print"This is not a right triangle."
And the problem is that when I get the numbers out I get one number, comma and another number. Or some combination of those (depending on the input) i was wondering if anyone could help me find a way to just get the numbers.
Upvotes: 0
Views: 82
Reputation: 73
def RightTriangleChecker(Number1,Number2,Number3):
AllNumbers=[Number1,Number2,Number3]
Hypotonuse=max(AllNumbers)
if(Number1**2+Number2**2==Number3**2):
print "This is a right triangle."
else:
print"This is not a right triangle."
def Retry():
Answer==raw_input("Retry?")
if (Answer=="Yes"):
TriangleLength=raw_input("What are the lengths of the sides? (Please put commas in-between each number)")
RightTriangleChecker(TriangleLength[1],TriangleLength[2],TriangleLength[3])
else:
exit(0)
Original=raw_input("Would you like to use this program?")
if (Original=="Yes"):
TriangleLength=raw_input("What are the lengths of the sides? (Please put commas in-between each number)")
RightTriangleChecker(TriangleLength[1],TriangleLength[2],TriangleLength[3])
if (Original=="No"):
exit(0)
Retry()
Upvotes: 0
Reputation: 56644
s = "26, 43, 25"
nums = [int(i) for i in s.split(",")]
also, I would rewrite your function as
def is_right_triangle(x, y, z):
a, b, c = sorted([x, y, z])
return a*a + b*b == c*c
Upvotes: 2