# Transforming a list

I am practicing sorting lists to display an alternative output to what the input is.

For Example, I have a list of temperatures and depending on the temperature, I want these to be displayed in a different list, but with the temperatures transformed into letters depending on what the temperature is.

So I have a list of temperatures of 39.3, 38.1, 38.5, 38.4, 39.1, 38.9, 39.5, 39.2 ,38.6, 38.0
I want Python to Print these temperatures as letters in a new list whereby all temperatures below 38.3 to display the letter L, temperatures between 38.3 and 39.2 inclusive to display the letter N and temperatures above 39.2 to display the letter H.

The code I have thus far is as follows:

#problem: add body temperatures to a new list according to temperatures.

#input: a possibly empty list of body temperartures in celcius.
body_temperature = [39.3,38.1,38.5,38.4,39.1,38.9,39.5,39.2,38.6,38.0]

#output: the body temperatures as low, normal or high.
temperature_levels =

for temperature in body_temperature:
levels = temperature + L, N, H
temperature_levels = temperature_levels + [levels]

print (temperature_levels)

I am stuck on how to get Python to transform these temperatures as letters. Any help would be appriciated.

Hi Oliver,

You say: “all temperatures below 38.3 to display the letter L”

``````if temperature < 38.3:
level = 'L'
``````

“temperatures between 38.3 and 39.2 inclusive to display the letter N”

``````if 38.3 <= temperature <= 39.2:
level = 'N'
``````

“temperatures above 39.2 to display the letter H”

``````if temperature > 39.2:
level = 'H'
``````

Now you have a code that represents the temperature as a letter ‘L’, ‘N’
or ‘H’. So then you can add it to your list of temperature levels:

``temperature_levels.append(level)``

Hi.

I’ve run the code and it still doesn’t work as it only prints the letter L once and not all the other letters for the temperatures listed

You’ve run what code?

I haven’t written your program for you. I’ve just given you the pieces

you need to write the program yourself.