私はBMI電卓を作成していますが、SI比を知らない人のためにコンバータにコードを追加しようとしています。問題は、私がこれを書いたのはあなたがあなたのSIを知っていて、Enterを押すだけです。あなたがSIの設定を聞いてくるのです。BMI電卓コンバータの選択肢を1つまたは他のものにしないようにする
print("\n")
print(" ------------------------------- ------------------------------- ")
print(" BMI Calculator ")
print("This calculator uses SI unites to determine BMI, use the converters below for pounds and feet.")
print(" If you know the SI units for just press enter. ")
print(" ------------------------------- ------------------------------- ")
none=()
c1=input("Please state your Weight in Pounds: ")
if c1 is none:
f1=float(c1)
w1=f1*.45659237
c2=input("Please state your Height in Feet: ")
if c2 is none:
f2=float(c2)
h1=f2*.3048
if c1 is not none and c2 is not none:
B=(w1/h1**2)
print(B)
else:
print("\n")
print("Great you know your SI Preferances: ")
W=input(("Please state your Weight in Kg: "))
H=input(("Please state your Height in m: "))
h=float(H)
w=float(W)
B=(w/h**2)
print(B)
何も入力しないと、次の質問に進むようにnone =()を設定します。あなたの体にSI比率を知っているなら、本質的にこれは機能します。 Enterを押してSI単位を入力すると、それは機能します。あなたのポンドと足を入力すると、それを無視して動きます。私はループでどこが間違っているのだろうと思っています。ここで
私はこの
B=(w1/h1**2)
NameError: name 'w1' is not defined
c1はNONE'あると '場合まあ、ええ、' w1'のみが定義されています」 'c1 is none'ならばアクセスしようとしています。また、なぜあなたはそのような「なし」をシャドーイングしているのですか? –
'none'は空のタプルです。 'input()'はユーザが単にEnterを押すと空文字列を返します。これらの2つのことは同じではありません。 –