解答例_2_7

解答例:練習問題_2_7(if~elif~else文+ブール演算 丸い的)

x, y = 65, 45

in_A = ((x - 60) ** 2 + (y - 30) ** 2) ** 0.5 <= 20.0
in_B = ((x - 45) ** 2 + (y - 50) ** 2) ** 0.5 <= 20.0
in_C = ((x - 75) ** 2 + (y - 50) ** 2) ** 0.5 <= 20.0

in_50 = in_A and in_B and in_C
in_30 = (in_A and in_B and not in_C) or (in_B and in_C and not in_A) or (in_C and in_A and not in_B)
in_10 = (in_A and not in_B and not in_C) or (in_B and not in_C and not in_A) or (in_C and not in_A and not in_B)

if in_50:
    score = 50
elif in_30:
    score = 30
elif in_10:
    score = 10
else:
    score = 0

print('score: ', score)

score: 30

確認

図を見ながら複数のポイントの x, y を代入して合っていることを確認してください。

タイトルとURLをコピーしました