Pythonの2ループは2回目の反復で失敗しながら、

Hamletta:

Iが温度推測(空間の温度)をユーザに要求したプログラムを作成し、この温度のために黒体スペクトルを算出し、測定データ対根平均二乗偏差を返します。ユーザーが再び推測するように要求されます。

私はまだ画像を埋め込むことができないので、ここで入力したコードは、です:

while True:
  temperature_guess = input("What is the temperature of the black body spectrum of space (in kelvin)?\
  Type 'stop' when you're happy with your estimate.")

  if temperature_guess == "stop":
    break

  else:
    T_guess = float(temperature_guess)

    print T_guess

    # Calculate intensities produced from measured wavelengths and user guess temperature

    intensities_guess=radiation(measured_lambda_metres,T_guess)

    print intensities_guess

    # Calculate root mean square deviation from measured values

    rmsd = rmsd(measured_intensity, intensities_guess)

    print "For your guessed temperature of" , T_guess , "kelvin, \
    the root mean square deviation from measured intensity data is" , "%.4g" %rmsd , \
    "to 4 significant figures."

私は停止することを指示した場合にプログラムがうまく一回の反復(1つの温度の推測)、休憩のために罰金を実行しますが、私は入力別の温度を、それが途中で失速した場合。それは温度入力を受け入れ、それに基づいて強度を計算しますが、根平均二乗偏差の計算に失敗したことを私は印刷コマンドから見ることができます。

どういうわけか「RMSD」機能は、それが二外出先で見るものを好みません。それはなぜそれをしますか?なぜ途中で止めますか?

Blckknght:

あなたは、上書きされるように見えるrmsdその戻り値によって機能を。ループ内で別の変数名を使用して、あなたはその問題を持っていません。

while True:
    # ...

    rmsd_value = rmsd(...)   # don't do rmsd = ... here, or you overwrite the function!

    # ...

おすすめ

転載: http://10.200.1.11:23101/article/api/json?id=408823&siteId=1