Luogu Question Writing Python Language | P5717 Triangle Classification

Learn Python from a young age! Record the questions in the Luogu Python learning and exam preparation process, and record every moment.

Attached is a summary post: Luogu’s Python language | Summary_Blog of a communicator who loves programming-CSDN Blog


[Title description]

Given the lengths of three line segments a, b, c, all are positive integers not greater than 10000. I plan to put these three line segments into a triangle. What kind of triangle can it be?

  • If the three line segments cannot form a triangle, output Not triangle;
  • If it is a right triangle, output Right triangle;
  • If it is an acute triangle, output Acute triangle;
  • If it is an obtuse triangle, output Obtuse triangle;
  • If it is an isosceles triangle, output Isosceles triangle;
  • If it is an equilateral triangle, output Equilateral triangle.

If this triangle meets more than one of the above conditions, please output them separately in the above order and separate them with newlines.

【enter】

Enter 3 integers a, b and c.

【Output】

Output several lines of judgment strings.

【Input sample】

3 3 3

【Output sample】

Acute triangle Isosceles triangle Equilateral triangle

[Detailed code explanation]

a,b,c = [int(i) for i in input().split()]  
if a>b: a,b = b,a  
if b>c: b,c = c,b
if a>b: a,b = b,a
t1 = a*a + b*b  
t2 = c*c 
if a+b<=c:  
    print("Not triangle")
else:  
    if t1==t2: 
        print("Right triangle")  
    if t1>t2:  
        print("Acute triangle")  
    if t1<t2: 
        print("Obtuse triangle")  
    if a == b or b == c:  
        print("Isosceles triangle") 
    if a == b == c: 
        print("Equilateral triangle")

【operation result】

1 14 5
Not triangle

Guess you like

Origin blog.csdn.net/guolianggsta/article/details/132778708