Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJose Coto
11,466 PointsFahrenheit to celsius
I am trying to make a list with only the Celsius values that are within a range. I'm trying to do it with a list comprehension but the code down does not seem to work.
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsHere's one solution:
# ipython3 fahrenheit to celsius
In [26]: lower_limit = 1
In [27]: upper_limit = 200
In [28]: fahrenheit = [-40, 0, 32, 122, 212]
In [29]: celsius = [(x-32)*5/9 for x in fahrenheit if x > lower_limit and x < upper_limit]
In [30]: celsius
Out[30]: [0.0, 50.0]
Jose Coto
11,466 PointsHi Chris,
Thanks for your help, as always. Your solution works, of course. I just was wondering why mine didn't given that, in essence, is the same as yours.
Chris Freeman
Treehouse Moderator 68,441 PointsCan you post your code. Let's figure out what's different
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsCan you post the code you've tried so far?