2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【python】即興で3角形の辺の長さの和を入力して、ピタゴラスの定理が成立するかチェックしてみた

Posted at

はじめに

プログラムコンテストの題材で、三角形の3辺の和の長さを整数で入力し、ピタゴラスの定理が成立する(直角三角形)かどうか判定するプログラムを実装しました。

ソースコード

ソースコードは下記になります

num = int(input())
count = 0
for b in range(1,num):
    for c in range(1,num-b):
        a = num - b - c

        ans1 = pow(a,2)
        ans2 = pow(b,2)
        ans3 = pow(c,2)
        ans4 = ans2 + ans3
        if ans1 == ans4:
            count += 1


if count >= 1:
    print("YES")
else:
    print("NO")

実行結果

実行結果は下記の画像です。

tedt1.jpg

最後に

競技プログラミングの課題に挑戦しました

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?