This is my code where I had to create it so it allows
However, the output part doesn't seem like working. I am new to this type of coding, so please help?
Length1 = raw_input()
Length2 = raw_input()
Length3 = raw_input()
print Length1
print Length2
print Length3
print Length1 == Length2
print Length2 == Length3
print Length1 == Length3
if Length1 == Length2 is True:
print "Isosceles"
else:
print "Not Isosceles"
if Length2 == Length3 is True:
print "Isosceles"
else:
print "Not Isosceles"
if Length1 == Length3 is True:
print "Isosceles"
else:
print "Not Isosceles"
The problem is that Python interprets
if Length1 == Length2 is True:
like
if Length1 == Length2 and Length2 is True:
Comparison operators, like <, ==, or is are chained. This is very useful for, e.g. a < b < c, but it can also result in some unexpected behaviour, as in your case.
Change those checks to
if (Length1 == Length2) is True:
or better, just use
if Length1 == Length2:
Alternatively, you could just count the number of distinct sides using a set:
distinct_sides = len(set([Length1, Length2, Length3]))
if distinct_sides == 1:
print "Equilateral"
if distinct_sides == 2:
print "Isosceles"
if distinct_sides == 3:
print "Scalene"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With