Kiểm tra chương trình tam giác vuông trong python

Trong hướng dẫn này, chúng ta sẽ tìm hiểu cách in một tam giác vuông bằng python 3. Một tam giác được gọi là tam giác vuông nếu một góc của nó bằng 90 độ hoặc góc vuông

Hai góc còn lại phụ thuộc vào độ dài cạnh của tam giác

Nếu hai cạnh tạo thành góc vuông bằng nhau hoặc nếu tam giác đó là tam giác cân thì hai góc còn lại luôn bằng 45 độ. Nếu hai cạnh không bằng nhau thì hai góc còn lại sẽ khác

Trong hướng dẫn này, chúng ta sẽ tạo một tam giác vuông cân, i. e. một góc là góc vuông và hai góc còn lại là 45 độ

In một tam giác vuông là một nhiệm vụ dễ dàng hơn so với in bất kỳ loại tam giác nào khác theo chương trình. Trong bài đăng trên blog này, tôi sẽ chỉ cho bạn từng bước giải quyết vấn đề này bằng lập trình

Đầu ra sẽ giống như dưới đây

Như bạn có thể thấy, chúng tôi đang thực sự in các hàng và cột ở đây. Bằng cách sử dụng các vòng lặp, chúng ta có thể đạt được kết quả như thế này. Chúng tôi sẽ chạy hai vòng. Một để in hàng và một để in cột

Đối với hàng đầu tiên, chúng ta cần in một cột, hai cột cho hàng thứ hai, ba cột cho hàng thứ ba, v.v.

Bạn có thể sử dụng bất kỳ vòng lặp nào [for hoặc while] mà bạn muốn. Trong ví dụ này, chúng tôi sẽ sử dụng vòng lặp 'for'

Vòng lặp bên ngoài sẽ chạy 6 lần trong ví dụ này. Giả sử nó chạy cho tôi từ 1 đến 6. Vòng lặp bên trong sẽ được sử dụng để in các số. nó sẽ chạy cho 1 đến tôi

  • Với i = 1 cho vòng lặp bên ngoài, j sẽ chạy cho 1 cho vòng lặp bên trong
  • Với i = 2 cho vòng ngoài, j sẽ chạy cho 1,2 cho vòng trong
  • Với i = 3 cho vòng lặp bên ngoài, j sẽ chạy cho 1,2,3 cho vòng lặp bên trong
  • Với i = 4 cho vòng ngoài, j sẽ chạy cho 1,2,3,4 cho vòng trong
  • Với i = 5 cho vòng ngoài, j sẽ chạy cho 1,2,3,4,5 cho vòng trong
  • Với i = 6 cho vòng ngoài, j sẽ chạy cho 1,2,3,4,5,6 cho vòng trong

Với mỗi lần vòng lặp bên trong chạy, chúng tôi sẽ in giá trị của 'i'. Vì vậy, với i = 1, nó sẽ chỉ in 1, với i = 2, nó sẽ chỉ in 2, v.v.

Ngoài ra, vòng lặp bên trong sẽ chạy trong khoảng thời gian 'i'. Đối với hàng đầu tiên, nó sẽ chạy một lần, hai lần cho hàng thứ hai, ba lần cho hàng thứ ba, v.v. Trên mỗi lần lặp của vòng lặp bên trong, chúng tôi đang in ký tự

Chương trình Python

Bạn có thể sao chép các chương trình từ đây

Cho ba tọa độ Descartes, nhiệm vụ là kiểm tra xem một tam giác vuông có thể được tạo bởi các tọa độ đã cho hay không. Nếu có thể tạo một tam giác vuông, hãy in Yes. Nếu không, in Không

ví dụ.  

Đầu vào. X1=0, Y1=5, X2=19, Y2=5, X3=0, Y3=0 
Đầu ra. Có 
Giải thích.
Chiều dài các điểm nối cạnh [X1, Y1] và [X2, Y2] là 12.
Chiều dài các điểm nối cạnh [X2, Y2] và [X3, Y3] là 15.
Chiều dài các điểm nối cạnh [X1, Y1] và [X3, Y3] là 9.
122 + 92 = 152.
Do đó có thể lập tam giác vuông.

Đầu vào. X1=5, Y1=14, X2=6, Y2=13, X3=8, Y3=7 
Đầu ra. Không 

Khuyến khích. Vui lòng thử cách tiếp cận của bạn trên {IDE} trước, trước khi chuyển sang giải pháp

Cách tiếp cận.
Ý tưởng là sử dụng Định lý Pythagoras để kiểm tra xem một tam giác vuông có khả thi hay không. Tính độ dài ba cạnh của tam giác bằng cách nối các tọa độ đã cho. Gọi các cạnh là A, B, C. Tam giác đã cho là tam giác vuông khi và chỉ khi A2 + B2 = C2. In Yes nếu điều kiện đúng. Nếu không, in Không.

Dưới đây là việc thực hiện các phương pháp trên

C++




// C++ program to implement

// the above approach

#include

using namespace std;

 

// Function to check if right-angled

[8, 10, 6]
0

[8, 10, 6]
1

// C++ program to implement0 // C++ program to implement1// C++ program to implement2 // C++ program to implement3// C++ program to implement2 // C++ program to implement5

// C++ program to implement6// C++ program to implement2 // C++ program to implement8// C++ program to implement2 // the above approach0

// C++ program to implement6// C++ program to implement2 // the above approach3// C++ program to implement2 // the above approach5

// the above approach6

// the above approach7// the above approach8

// the above approach7// C++ program to implement2 #include 1____32#include 3#include 4#include 5

#include 6#include 7____32#include 3#include 4using1

 

// the above approach7// C++ program to implement2 using4// C++ program to implement2#include 3#include 4using8

#include 6#include 7____32#include 3#include 4namespace4

 

// the above approach7// C++ program to implement2 namespace7// C++ program to implement2#include 3#include 4std;1

#include 6#include 7____32#include 3#include 4std;7

 

// the above approach7std;9

// the above approach7// Function to check if right-angled1 // Function to check if right-angled2

// Function to check if right-angled3// Function to check if right-angled4

// Function to check if right-angled5// Function to check if right-angled6

_______93____98____99

[8, 10, 6]
00

 

// the above approach7

[8, 10, 6]
02

_______93____98____105

[8, 10, 6]
00

[8, 10, 6]
07

 

[8, 10, 6]
08

// C++ program to implement2

[8, 10, 6]
10

// the above approach6

// the above approach7// C++ program to implement2

[8, 10, 6]
14

// the above approach7// C++ program to implement2

[8, 10, 6]
17

// the above approach7// C++ program to implement2 // C++ program to implement00

 

// the above approach7// C++ program to implement02

// C++ program to implement03// C++ program to implement04

 

// the above approach7// C++ program to implement06 // C++ program to implement07

[8, 10, 6]
07

Java




// C++ program to implement09

// C++ program to implement10 // C++ program to implement11

 

// C++ program to implement12 // C++ program to implement13

// the above approach7

// Function to check if right-angled

[8, 10, 6]
0

[8, 10, 6]
1

// C++ program to implement18 // C++ program to implement0 // C++ program to implement1// C++ program to implement2 // C++ program to implement3// C++ program to implement2 // C++ program to implement5

// C++ program to implement25// C++ program to implement2 // C++ program to implement8// C++ program to implement2 // the above approach0

// C++ program to implement25// C++ program to implement2 // the above approach3// C++ program to implement2 // the above approach5

// the above approach6

// the above approach7

// the above approach7// the above approach8

// the above approach7// C++ program to implement2 #include 1____32// C++ program to implement43// C++ program to implement44// C++ program to implement45

#include 6// C++ program to implement47// C++ program to implement2// C++ program to implement49// C++ program to implement44// C++ program to implement51

 

// the above approach7// C++ program to implement2 using4____32// C++ program to implement56// C++ program to implement44// C++ program to implement45

#include 6// C++ program to implement47// C++ program to implement2// C++ program to implement62// C++ program to implement44// C++ program to implement51

 

// the above approach7// C++ program to implement2 namespace7______32// C++ program to implement69// C++ program to implement44// C++ program to implement45

#include 6// C++ program to implement47// C++ program to implement2// C++ program to implement75// C++ program to implement44// C++ program to implement51

 

// the above approach7std;9

// the above approach7// Function to check if right-angled1 // C++ program to implement82// C++ program to implement83 // C++ program to implement84// C++ program to implement83 // C++ program to implement86// C++ program to implement83// C++ program to implement88

// Function to check if right-angled3// C++ program to implement90

// C++ program to implement91// C++ program to implement92

// Function to check if right-angled3// C++ program to implement94// Function to check if right-angled9// C++ program to implement51

// the above approach7

[8, 10, 6]
02

_______93____394____105____351

[8, 10, 6]
07

 

[8, 10, 6]
08

// the above approach05 // C++ program to implement18 // C++ program to implement0 // the above approach08

// the above approach6

// the above approach7// C++ program to implement2 // the above approach12// C++ program to implement83// the above approach14// C++ program to implement44

[8, 10, 6]
00

// the above approach7// C++ program to implement2 // the above approach19// C++ program to implement83// the above approach21// the above approach22

[8, 10, 6]
00

// the above approach7// C++ program to implement2 // the above approach26// the above approach27// the above approach28// C++ program to implement44

[8, 10, 6]
00

// the above approach7

_______47____433

[8, 10, 6]
07

[8, 10, 6]
07

 

// the above approach36

Python3




// the above approach37

// the above approach38

 

// the above approach39

// the above approach40

// the above approach41

// the above approach42 // C++ program to implement02

// C++ program to implement03// the above approach45

// the above approach7

// the above approach7// the above approach48

// the above approach7// the above approach50// the above approach51 // C++ program to implement47// C++ program to implement2// C++ program to implement47#include 4// the above approach56// the above approach57 // the above approach58// C++ program to implement44// the above approach60// the above approach61

// C++ program to implement91// C++ program to implement2// C++ program to implement47#include 4____466// the above approach57 // the above approach68// C++ program to implement44// the above approach70

// the above approach7// the above approach72// the above approach51 // C++ program to implement47// C++ program to implement2// C++ program to implement47#include 4// the above approach78// the above approach57 // the above approach80// C++ program to implement44// the above approach60// the above approach61

// C++ program to implement91// C++ program to implement2// C++ program to implement47#include 4____488// the above approach57 // the above approach90// C++ program to implement44// the above approach70

// the above approach7// the above approach94// the above approach51 // C++ program to implement47// C++ program to implement2// C++ program to implement47#include 4// the above approach78// the above approach57 // the above approach58// C++ program to implement44// the above approach60// the above approach61

// C++ program to implement91// C++ program to implement2// C++ program to implement47#include 4____488// the above approach57 // the above approach68// C++ program to implement44// the above approach70

// the above approach7

// the above approach7____517

// the above approach7// Function to check if right-angled1 // C++ program to implement82// C++ program to implement83 #include 22 #include 23// C++ program to implement83 #include 22 #include 26// C++ program to implement83#include 3#include 22

// Function to check if right-angled3#include 31// the above approach51// the above approach51 #include 34// the above approach61 #include 36#include 37 // the above approach72// the above approach51// the above approach51 #include 31// the above approach61 #include 36#include 37

// C++ program to implement91// the above approach94// the above approach51// the above approach51 #include 31// the above approach61 #include 51

// Function to check if right-angled3____553____347// Function to check if right-angled9#include 3

_______47____102____559

// Function to check if right-angled3#include 53____347

[8, 10, 6]
05#include 3

 

#include 65

// Function to check if right-angled1 #include 67____451____451#include 70#include 59

// the above approach7

// the above approach7#include 74// the above approach51 // C++ program to implement83#include 77// the above approach51 // C++ program to implement83#include 80// the above approach51 // the above approach27

[8, 10, 6]
00

// the above approach7#include 85// the above approach51 // C++ program to implement44#include 88// the above approach51 // the above approach22#include 91// the above approach51 // C++ program to implement44

[8, 10, 6]
00

Chủ Đề