#Modified code def triangle_type(a, b, c): ''' Return a string indicating the type of triangle (Equilateral, Isosceles, Scalene, Impossible) '''
Modified code
def triangle_type(a, b, c):
'''
Return a string indicating the type of triangle
(Equilateral, Isosceles, Scalene, Impossible)
'''
a, b, c = sorted([a, b, c])
if a + b <= c:
return 'Impossible'
if a != b != c:
return 'Scalene'
if a == c:
return 'Equilateral'
return 'Isosceles'
def main():
a = input("Length of side a: ")
b = input("Length of side b: ")
c = input("Length of side c: ")
print(f"({a}, {b}, {c}) is a {triangle_type(a, b, c)} triangle")
if __name__ == "__main__":
main()
Further improvement
#Further improvement
UseUse the doctest
module to write the tests:
#Modified code def triangle_type(a, b, c): ''' Return a string indicating the type of triangle (Equilateral, Isosceles, Scalene, Impossible) '''
a, b, c = sorted([a, b, c])
if a + b <= c:
return 'Impossible'
if a != b != c:
return 'Scalene'
if a == c:
return 'Equilateral'
return 'Isosceles'
def main():
a = input("Length of side a: ")
b = input("Length of side b: ")
c = input("Length of side c: ")
print(f"({a}, {b}, {c}) is a {triangle_type(a, b, c)} triangle")
if __name__ == "__main__":
main()
#Further improvement
Use the doctest
module to write the tests:
Modified code
def triangle_type(a, b, c):
'''
Return a string indicating the type of triangle
(Equilateral, Isosceles, Scalene, Impossible)
'''
a, b, c = sorted([a, b, c])
if a + b <= c:
return 'Impossible'
if a != b != c:
return 'Scalene'
if a == c:
return 'Equilateral'
return 'Isosceles'
def main():
a = input("Length of side a: ")
b = input("Length of side b: ")
c = input("Length of side c: ")
print(f"({a}, {b}, {c}) is a {triangle_type(a, b, c)} triangle")
if __name__ == "__main__":
main()
Further improvement
Use the doctest
module to write the tests:
a, b, c = sorted([a, b, c])
if a + b <= c:
# N.B. automatically catches a < 0, since b <= c
return 'Impossible'
if a != b != c:
return 'Scalene'
elif a == c:
return 'Equilateral'
else:
return 'Isosceles'
a, b, c = sorted([a, b, c])
if a + b <= c:
return 'Impossible'
if a != b != c:
return 'Scalene'
elifif a == c:
return 'Equilateral'
else:
return 'Isosceles'
def main():
a = input("Length of side a: ")
b = input("Length of side b: ")
c = input("Length of side c: ")
print(f"({a}, {b}, {c}) is a {triangle_type(a, b, c)} triangle")
if __name__ == "__main__":
main()
def triangle_type(a, b, c):
'''
Return a string indicating the type of triangle
(Equilateral, Isosceles, Scalene, Impossible)
>>> triangle_type(1, 1, 2)
'Impossible'
>>> triangle_type(-1, -1, -1)
'Impossible'
>>> triangle_type(1, 1.0, 1)
'Equilateral'
>>> triangle_type(1, 2, 2)
'Isosceles'
>>> triangle_type(2, 3, 2)
'Isosceles'
>>> triangle_type(2, 3, 4)
'Scalene'
'''
a, b, c = sorted([a, b, c])
if a + b <= c:
return 'Impossible'
if a != b != c:
return 'Scalene'
elifif a == c:
return 'Equilateral'
else:
return 'Isosceles'
if __name__ == "__main__":
import doctest
doctest.testmod()
a, b, c = sorted([a, b, c])
if a + b <= c:
return 'Impossible'
if a != b != c:
return 'Scalene'
elif a == c:
return 'Equilateral'
else:
return 'Isosceles'
a, b, c = sorted([a, b, c])
if a + b <= c:
return 'Impossible'
if a != b != c:
return 'Scalene'
elif a == c:
return 'Equilateral'
else:
return 'Isosceles'
def main():
a = input("Length of side a: ")
b = input("Length of side b: ")
c = input("Length of side c: ")
print(f"({a}, {b}, {c}) is a {triangle_type(a, b, c)} triangle")
if __name__ == "__main__":
main()
def triangle_type(a, b, c):
'''
Return a string indicating the type of triangle
(Equilateral, Isosceles, Scalene, Impossible)
>>> triangle_type(1, 1, 2)
'Impossible'
>>> triangle_type(-1, -1, -1)
'Impossible'
>>> triangle_type(1, 1.0, 1)
'Equilateral'
>>> triangle_type(1, 2, 2)
'Isosceles'
>>> triangle_type(2, 3, 2)
'Isosceles'
>>> triangle_type(2, 3, 4)
'Scalene'
'''
a, b, c = sorted([a, b, c])
if a + b <= c:
return 'Impossible'
if a != b != c:
return 'Scalene'
elif a == c:
return 'Equilateral'
else:
return 'Isosceles'
if __name__ == "__main__":
import doctest
doctest.testmod()
a, b, c = sorted([a, b, c])
if a + b <= c:
# N.B. automatically catches a < 0, since b <= c
return 'Impossible'
if a != b != c:
return 'Scalene'
elif a == c:
return 'Equilateral'
else:
return 'Isosceles'
a, b, c = sorted([a, b, c])
if a + b <= c:
return 'Impossible'
if a != b != c:
return 'Scalene'
if a == c:
return 'Equilateral'
return 'Isosceles'
def main():
a = input("Length of side a: ")
b = input("Length of side b: ")
c = input("Length of side c: ")
print(f"({a}, {b}, {c}) is a {triangle_type(a, b, c)} triangle")
if __name__ == "__main__":
main()
def triangle_type(a, b, c):
'''
Return a string indicating the type of triangle
(Equilateral, Isosceles, Scalene, Impossible)
>>> triangle_type(1, 1, 2)
'Impossible'
>>> triangle_type(-1, -1, -1)
'Impossible'
>>> triangle_type(1, 1.0, 1)
'Equilateral'
>>> triangle_type(1, 2, 2)
'Isosceles'
>>> triangle_type(2, 3, 2)
'Isosceles'
>>> triangle_type(2, 3, 4)
'Scalene'
'''
a, b, c = sorted([a, b, c])
if a + b <= c:
return 'Impossible'
if a != b != c:
return 'Scalene'
if a == c:
return 'Equilateral'
return 'Isosceles'
if __name__ == "__main__":
import doctest
doctest.testmod()
def triangle_type(a, b, c):
'''
Return a string indicating the type of triangle
(Equilateral, Isosceles, Scalene, Impossible)
>>> triangle_type(1, 1, 2)
'Impossible'
>>> triangle_type(-1, -1, -1)
'Impossible'
>>> triangle_type(1, 1.0, 1)
'Equilateral'
>>> triangle_type(1, 2, 2)
'Isosceles'
>>> triangle_type(2, 3, 2)
'Isosceles'
>>> triangle_type(2, 3, 4)
'Scalene'
'''
a, b, c = sorted([a, b, c])
if a + b <= c:
return 'Impossible'
if a != b != c:
return 'Scalene'
elif a == c:
return 'Equilateral'
else:
return 'Isosceles'
if __name__ == "__main__":
import doctest
doctest.testmod()
def triangle_type(a, b, c):
'''
Return a string indicating the type of triangle
(Equilateral, Isosceles, Scalene, Impossible)
>>> triangle_type(1, 1, 2)
'Impossible'
>>> triangle_type(-1, -1, -1)
'Impossible'
>>> triangle_type(1, 1.0, 1)
'Equilateral'
>>> triangle_type(1, 2, 2)
'Isosceles'
>>> triangle_type(2, 3, 4)
'Scalene'
'''
a, b, c = sorted([a, b, c])
if a + b <= c:
return 'Impossible'
if a != b != c:
return 'Scalene'
elif a == c:
return 'Equilateral'
else:
return 'Isosceles'
if __name__ == "__main__":
import doctest
doctest.testmod()
def triangle_type(a, b, c):
'''
Return a string indicating the type of triangle
(Equilateral, Isosceles, Scalene, Impossible)
>>> triangle_type(1, 1, 2)
'Impossible'
>>> triangle_type(-1, -1, -1)
'Impossible'
>>> triangle_type(1, 1.0, 1)
'Equilateral'
>>> triangle_type(1, 2, 2)
'Isosceles'
>>> triangle_type(2, 3, 2)
'Isosceles'
>>> triangle_type(2, 3, 4)
'Scalene'
'''
a, b, c = sorted([a, b, c])
if a + b <= c:
return 'Impossible'
if a != b != c:
return 'Scalene'
elif a == c:
return 'Equilateral'
else:
return 'Isosceles'
if __name__ == "__main__":
import doctest
doctest.testmod()