私はaとbを同じにして、aとbが同じで、cとdが同じでなければならない、入力した形が平行四辺形であるかどうかを知るプログラムを作るのに助けが必要です
a, b, c, d = sorted(
float(input("Enter length of side {}: ".format(x))) for x in 'ABCD'
)
if a == b and c == d:
# parallel
私はaとbを同じにして、aとbが同じで、cとdが同じでなければならない、入力した形が平行四辺形であるかどうかを知るプログラムを作るのに助けが必要です
a, b, c, d = sorted(
float(input("Enter length of side {}: ".format(x))) for x in 'ABCD'
)
if a == b and c == d:
# parallel
Bと異なる場合があります変数を文字列ではなく変数と比較する必要があります。
play = True
while play:
a = float(input("Enter length of side A: "))
b = float(input("Enter length of side B: "))
c = float(input("Enter length of side C: "))
d = float(input("Enter length of side D: "))
if a == b and c == d:
print("It's a parallelogram")
elif a == c and b == d:
print("It's a parallelogram")
elif b == c and a == d:
print("It's a parallelogram")
else:
print("It is not a parallelogram")
あなたは、さらにテストを簡素化し、関数内のI/Oを抽出することができます:
def get_values():
a = float(input("Enter length of side A: "))
b = float(input("Enter length of side B: "))
c = float(input("Enter length of side C: "))
d = float(input("Enter length of side D: "))
return a, b, c, d
play = True
while play:
a, b, c, d = get_values()
if (a == b and c == d) or (a == c and b == d) or (b == c and a == d):
print("It's a parallelogram")
else:
print("It is not a parallelogram")
ではありません。それを保つ? –
あなたはそれらの値を得るためにそれを保つ。 – schwobaseggl
@NickDamore答えを更新し、入力読書を乾燥させた。 – schwobaseggl
ます:彼らは、次のようなSTHとなど文字列リテラル'a', 'b'
が、実際の変数名を使用しないように、あなたのロジックを簡素化することができ
play = True
while play:
a = float(input("Enter length of side A: "))
b = float(input("Enter length of side B: "))
c = float(input("Enter length of side C: "))
d = float(input("Enter length of side D: "))
if 'a' == 'b' and 'c' == 'd':
print("It's a parallelogram")
elif 'a' == 'c' and 'b' == 'd':
print("It's a parallelogram")
elif 'b' == 'c' and 'a' == 'd':
print("It's a parallelogram")
else:
print("It is not a parallelogram")
continue
ああ大丈夫、私は機能を作ったとは思わなかった –
それはしばらくすると、 I/Oを分離し、少数のクラスと機能に制限する習慣。 –
あなたの質問は何ですか? – tyteen4a03
また、 ''a == 'b''はリテラル文字列" a "とリテラル文字列" b "を互いに比較しています。これは常にFalseになります。あなたが 'a == b 'なら、 – tyteen4a03
はそれが平行四辺形ではないと言っています。 –