社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

Python 2 while循环在第二次迭代中失败

Hamletta • 5 年前 • 1563 次点击  

我创建了一个程序,要求用户进行温度猜测(空间温度),然后计算这个温度的黑体光谱,并返回与测量数据的均方根偏差。然后要求用户再次猜测:

这是输入的代码,因为我还不能嵌入图像:

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."

程序在一次迭代中运行良好(一次温度猜测),如果我让它停止,它会很好地中断,但是如果我输入另一个温度,它会在中途停止。我可以从print命令中看到,它接受温度输入并基于此计算强度,但在均方根偏差计算中失败。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/57281
 
1563 次点击  
文章 [ 1 ]  |  最新文章 5 年前