Python 3.x 列表中的摄氏度到华氏度循环
我试图创建一个从摄氏0-100度到华氏0.5度的温度转换列表。这是我到目前为止所做的,但我似乎无法让循环正确运行,因为它以摄氏度:0华氏度:0开始;我需要它以摄氏度:0华氏度:32(正确的转换)开始Python 3.x 列表中的摄氏度到华氏度循环,python-3.x,Python 3.x,我试图创建一个从摄氏0-100度到华氏0.5度的温度转换列表。这是我到目前为止所做的,但我似乎无法让循环正确运行,因为它以摄氏度:0华氏度:0开始;我需要它以摄氏度:0华氏度:32(正确的转换)开始 count=0 摄氏度=0 而(摄氏为什么不写一个函数呢 def toFarenheit(celsius): return (9.0/5.0) * celsius + 32 def toCelsius(farenheit): return (farenheit - 32) * (5
count=0
摄氏度=0
而(摄氏为什么不写一个函数呢
def toFarenheit(celsius):
return (9.0/5.0) * celsius + 32
def toCelsius(farenheit):
return (farenheit - 32) * (5.0 / 9.0)
# I don't actually use this method, but it's still good to have
然后,您可以执行以下操作:
for y in range(0,200):
x = y / 2.0
print("Celsius: ", x, ", Farenheit: ", toFarenheit(x))
我想你要找的更像这样:
celsius = 0
while celsius <= 100:
fahrenheit = celsius * 9.0/5.0 + 32
print ('Celsius:', celsius, 'Fahrenheit:', fahrenheit)
celsius += 0.5
摄氏度=0
摄氏度
celsius = 0
while celsius <= 100:
fahrenheit = celsius * 9.0/5.0 + 32
print ('Celsius:', celsius, 'Fahrenheit:', fahrenheit)
celsius += 0.5