私はコーディングの初心者です。私はPythonを使用して2次方程式の電卓を作成しようとしています。ifステートメントでブール演算子を使用する
while True:
print("""
Welcome to DJIGURDA Supreme Quadratic Calculator
Please enter three values in the form of /'ax^2 + bx +c/'. """)
a = input("a (first constant)")
b = input("b (second constant)")
c = input("c (third constant)")
if not a.isalpha and not b.isalpha and not c.isalpha:
d = (float(b)**2) - (4 * float(a) * float(c))
print(d)
if d >= 0:
x_1 = (float(-b) + (d**0.5))/(2*float(a))
x_2 = (float(-b) - (d**0.5))/(2*float(a))
print("The first variable is equal to %s./n The second variable is equal to %s")[str(x_1), str(x_2)]
else:
print("No real roots.")
else:
print("Please enter numerical values.")
このコードでは、「数値を入力してください」と返されます。コードが最初の "if"ステートメントを通過しないのはなぜですか?
ブラケット。それぞれのブール 'if'セクションの周りに'() 'を入れる必要があります。 – Tim
'(a.isalpha()ではなくif(b.isalpha()ではない)、(c.isalphaではなく)' – Tim
'a.isalpha()'を呼び出す必要があります。 –