using functions to display numbers in a list

后端 未结 4 1166
面向向阳花
面向向阳花 2021-01-29 14:09

I have a list of numbers and I have to use a function to display them in celsius, they are in fahrenheit now.

nums = [30,34,40,36,36,28,29,32,34,44,36,35,28,33,         


        
4条回答
  •  忘掉有多难
    2021-01-29 14:27

    Your function seems to take as input a single number, yet you're giving it a list of numbers. If you want to generate a list of converted numbers using that function, you can use list comprehension:

    cels = [fahrenToCel(fah) for fah in nums]
    

提交回复
热议问题