Hướng dẫn write a python program to check whether the triangle is equilateral, isosceles or scalene triangle. - viết chương trình python để kiểm tra xem tam giác đó là tam giác đều, cân hay tam giác vô hướng.

Cập nhật lần cuối vào ngày 19 tháng 8 năm 2022 21:50:48 (UTC/GMT +8 giờ)

Python có điều kiện: Bài tập - 36 với giải pháp

Viết một chương trình Python để kiểm tra một tam giác là công bằng, isosceles hoặc scalene. Lưu ý: Một tam giác đều là một tam giác trong đó cả ba cạnh đều bằng nhau. Một tam giác scalene là một tam giác có ba mặt không đồng đều. Một tam giác cân là một tam giác với (ít nhất) hai cạnh bằng nhau.
Note :
An equilateral triangle is a triangle in which all three sides are equal.
A scalene triangle is a triangle that has three unequal sides.
An isosceles triangle is a triangle with (at least) two equal sides.

Trình bày bằng hình ảnh:

Hướng dẫn write a python program to check whether the triangle is equilateral, isosceles or scalene triangle. - viết chương trình python để kiểm tra xem tam giác đó là tam giác đều, cân hay tam giác vô hướng.

Giải pháp mẫu:

Mã Python:

print("Input lengths of the triangle sides: ")
x = int(input("x: "))
y = int(input("y: "))
z = int(input("z: "))

if x == y == z:
	print("Equilateral triangle")
elif x==y or y==z or z==x:
	print("isosceles triangle")
else:
	print("Scalene triangle")

Đầu ra mẫu:

x: 6                                                                                                          
y: 8                                                                                                          
z: 12                                                                                                         
Scalene triangle  

Sơ đồ :

Hướng dẫn write a python program to check whether the triangle is equilateral, isosceles or scalene triangle. - viết chương trình python để kiểm tra xem tam giác đó là tam giác đều, cân hay tam giác vô hướng.

Trực quan hóa thực thi mã Python:

Công cụ sau đây trực quan hóa những gì máy tính đang làm từng bước khi nó thực hiện chương trình đã nói:

Trình chỉnh sửa mã Python:

Có một cách khác để giải quyết giải pháp này? Đóng góp mã của bạn (và nhận xét) thông qua Disqus.

Trước đây: Viết chương trình Python để kiểm tra một chuỗi đại diện cho một số nguyên hay không? Tiếp theo: Viết một chương trình Python đọc hai số nguyên đại diện cho một tháng và ngày và in mùa cho tháng đó. Write a Python program to check a string represent an integer or not?
Next: Write a Python program that reads two integers representing a month and day and prints the season for that month and day.

Python: Lời khuyên trong ngày

Số nguyên, phao, dây, booleans và bộ dữ

Khi chúng ta gán một biến cho một loại bất biến như số nguyên, phao, chuỗi, booleans và bộ dữ liệu, thì biến này chỉ vào một đối tượng trong bộ nhớ.

Trong trường hợp chúng tôi gán cho biến đó, một giá trị khác, đối tượng gốc vẫn còn trong bộ nhớ, nhưng biến chỉ vào nó bị mất:

number = 1
print(id(number))  # 4325215472
print(id(1))  # 4325215472

number = 3
print(id(number))  # 4325215536
print(id(1))  # 4325215472

Tham khảo: https://bit.ly/3ndmjen


n = int (input ()).

Làm thế nào để bạn tìm thấy tam giác isosceles trong Python?

Mã tam giác isosceles trong Python.

  • In ("Chiều dài đầu vào của các cạnh tam giác:").
  • x = int (đầu vào ("x:")).
  • n = int (input ()).

    Làm thế nào để bạn tìm thấy tam giác isosceles trong Python?

    Mã tam giác isosceles trong Python.

    In ("Chiều dài đầu vào của các cạnh tam giác:").X, Y, and Z representing the three sides of a triangle, the task is to check whether the triangle formed by the given sides is equilateral, isosceles, or scalene.

    x = int (đầu vào ("x:")). A triangle is said to be equilateral triangle if all the sides are equal. If X, Y, Z are three sides of the triangle. Then, the triangle is equilateral only if X = Y = Z.

    y = int (đầu vào ("y:")). A triangle is said to be an isosceles triangle if any of its two sides are equal. If X, Y, Z are three sides of the triangle.Then, the triangle is isosceles if either X = Y or X = Z or Y = Z.

    z = int (đầu vào ("z:")). A triangle is said Scalene Triangle if none of its sides is equal.

    Examples:

    Nếu x == y == z:. X = 6, Y = 8, Z = 10
    Output: Scalene Triangle
    Explanation:
    Since all the sides of the given triangle are unequal, the triangle is scalene.

    In ("Tam giác cân bằng"). X = 10, Y = 10, Z = 10
    Output: Equilateral Triangle
    Explanation:
    Since all the sides of the given triangle are equal.

    Elif x == y hoặc y == z hoặc z == x:. Follow the steps below to solve the problem:

    1. Công thức cho tam giác trong Python là gì?X = Y and Y = Z. If found to be true, print “Equilateral Triangle”.
    2. s = (a + b + c) / 2. # Tính diện tích. diện tích = (s*(s-a)*(s-b)*(s-c)) ** 0,5. in ('diện tích của tam giác là %0,2f' %diện tích)X = Y or X = Z or Y = Z. If found to be true, print “Isosceles Triangle”.
    3. Xem thảo luận

    Cải thiện bài viết

    C++

    #include

    Lưu bài viết

    Đọc

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    5

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    9
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    11
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    1229____29
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    14

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    9
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    0
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    1
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    2

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    03
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    04 checkTriangle(9

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    9
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    0
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    9
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    2

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    4

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    9
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    0#include 5
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    2

    #include 7

    int #include 9

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    5

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6int using3

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6using5

    #include 7

    Java

    using7 using8

    using9 void

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    5

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    7 std;1

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    9std;3
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    1std;5

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    4
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    7 std;9

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    9std;3
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    9std;5

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    4

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    9std;3#include 5std;5

    #include 7

    checkTriangle(1 using9 void checkTriangle(4

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    5

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6int checkTriangle(8checkTriangle(9int0int1____92

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6using5

    #include 7

    #include 7

    Python3

    int9

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    00

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    7
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    03
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    044____104

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    9
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    11
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    12
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    1
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    14

    Is

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    9
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    11
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    1229____29
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    14

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    4
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    38

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    9
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    11
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    12#include 5
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    14

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    03
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    04 checkTriangle(9

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    06
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    04 int1

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    25
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    04 int3

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    53

    C#

    using

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    55

    using7 using8

    using9 void

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    5

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    7 std;1

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    9
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    72
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    1std;5

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    4
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    7 std;9

    checkTriangle(1 using9 void checkTriangle(4

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    4

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    9
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    72#include 5std;5

    #include 7

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6int checkTriangle(8checkTriangle(9int0int1____92

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    5

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6int using3

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6using5

    #include 7

    #include 7

    int9 x: 6 y: 8 z: 12 Scalene triangle 00

    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    02

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    7
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    03
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    044____104

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    5

    Is

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    9
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    10
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    1std;5

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    9
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    11
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    1229____29
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    14

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    9
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    10
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    9std;5

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    03
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    04 checkTriangle(9

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    9
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    10#include 5std;5

    #include 7

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6
    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    29

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    6using5

    number = 1
    print(id(number))  # 4325215472
    print(id(1))  # 4325215472
    
    number = 3
    print(id(number))  # 4325215536
    print(id(1))  # 4325215472
    
    32

    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    06
    x: 6                                                                                                          
    y: 8                                                                                                          
    z: 12                                                                                                         
    Scalene triangle  
    
    04 int1
    O(1)
    Auxiliary Space: O(1)


    Làm thế nào để bạn xác định xem một tam giác có phải là đồng phân công bằng hay scalene không?

    Nếu không có cạnh của tam giác bằng nhau (có chiều dài bằng nhau), tam giác là scalene.Nếu hai hoặc nhiều cạnh hình tam giác bằng nhau, tam giác là đồng phân.Nếu cả ba cạnh của một tam giác đều bằng nhau, thì đó là công bằng.. If two or more of the triangles sides are equal, the triangle is isosceles. If all three of the sides of a triangle are equal, it is equilateral.

    Làm thế nào để bạn mã hóa một tam giác đều trong Python?

    Tam giác def (n):.
    Đối với i trong phạm vi (1, n+1):.
    in ('' * n, end = '').
    in ('*'* (i)).
    n -= 1 ..
    n = int (input ()).
    triangle(n).

    Làm thế nào để bạn tìm thấy tam giác isosceles trong Python?

    Mã tam giác isosceles trong Python..
    In ("Chiều dài đầu vào của các cạnh tam giác:").
    x = int (đầu vào ("x:")).
    y = int (đầu vào ("y:")).
    z = int (đầu vào ("z:")).
    Nếu x == y == z:.
    In ("Tam giác cân bằng").
    Elif x == y hoặc y == z hoặc z == x:.

    Công thức cho tam giác trong Python là gì?

    s = (a + b + c) / 2. # Tính diện tích.diện tích = (s*(s-a)*(s-b)*(s-c)) ** 0,5.in ('diện tích của tam giác là %0,2f' %diện tích). # calculate the area. area = (s*(s-a)*(s-b)*(s-c)) ** 0.5. print('The area of the triangle is %0.2f' %area)