##### Temp Converter with Kelvin
 Temp Converter with Kelvin vader33 Unladen Swallow Posts: 3 Threads: 1 Joined: Oct 2016 Reputation: 0 Oct-01-2016, 02:32 PM Hey guys, new to the forum, and to coding. My college programming class has us writing code that will convert from Fahrenheit to Celsius and to Kelvin. I thought I had everything correct, but when I run the code and give it a temperature to convert, all it does is read that same temp back as the converted one. Any help would be appreciated! Thanks! [Image: nyik1w.png] -Vader Reply Exponential_Sinusoid Unladen Swallow Posts: 2 Threads: 0 Joined: Sep 2016 Reputation: 0 Oct-01-2016, 02:40 PM You're not changing the 'temp' variable at all, and then using it as the output. In essence, you're asking for the temperature and the measurement type, then asking for the conversion to make. You then make that conversion and print out the temperature that they gave you. Reply ichabod801 Bunny Rabbit Posts: 4,231 Threads: 97 Joined: Sep 2016 Reputation: 273 Oct-01-2016, 02:41 PM In the future, please use code tags. The problem is that you are outputting tempFormatted, which is calculated based on temp. You need to output the variables you calculated in the "#Make the conversion" section of your code. Craig "Ichabod" O'Brien - xenomind.com I wish you happiness. Recommended Tutorials: BBCode, functions, classes, text adventures Reply ichabod801 Bunny Rabbit Posts: 4,231 Threads: 97 Joined: Sep 2016 Reputation: 273 Oct-01-2016, 02:46 PM Also, look at your input checking section. Note that this is a much easier way to do it: ```badInput = True while badInput:    which = input('Enter selection: ')    if which in ['F', 'C', 'K']:        badInput = False```That reduces three conditions to one condition. But then, if you just have one condition, you can stick that condition in the while statement: ```which = 'X' while which not in ['F', 'C', 'K']:    which = input('Enter selection: ')``` Craig "Ichabod" O'Brien - xenomind.com I wish you happiness. Recommended Tutorials: BBCode, functions, classes, text adventures Reply vader33 Unladen Swallow Posts: 3 Threads: 1 Joined: Oct 2016 Reputation: 0 Oct-01-2016, 10:24 PM (Oct-01-2016, 02:41 PM)ichabod801 Wrote: In the future, please use code tags. The problem is that you are outputting tempFormatted, which is calculated based on temp. You need to output the variables you calculated in the "#Make the conversion" section of your code. Sorry about the lack of code tags. I'll make sure to use those from now on. I see what you're saying about the output variables, but didn't I do that here? Example: ```if which =='K':    fahrenTemp = (temp - 9/5) -459.67    celsiusTemp = temp - 273.15``` Reply ichabod801 Bunny Rabbit Posts: 4,231 Threads: 97 Joined: Sep 2016 Reputation: 273 Oct-01-2016, 11:35 PM You calculate the output variables, but you don't actually use them in the output. You output tempFormatted, but that is calculated off of temp, which is the original input. You need to calculate tempFormatted from fahrenTemp or celsiusTemp, and then print that. But not that you need to figure out which two calculated variables to output based on the which variable. You are basically already do that when you are calculating them, so you should probably just output them when you calculate them. Craig "Ichabod" O'Brien - xenomind.com I wish you happiness. Recommended Tutorials: BBCode, functions, classes, text adventures Reply Vexis Unladen Swallow Posts: 2 Threads: 0 Joined: Oct 2016 Reputation: 0 Oct-02-2016, 03:39 AM I'm not exactly understanding your conversion methods, but this is how I would do it: ```print("K for kelvin, C for Celsius, F for Fahrenheit ") option = None while not option in ['c', 'f', 'k']:    option = input("Enter Selection: ").lower() temp = float(input("Input Temperature in {}: ".format(option.upper()))) conversions = dict(kelvin=None, celsius=None, fahrenheit=None) if option == 'k':    conversions.update([('celsius', temp-273.16), ('fahrenheit', (temp+273.16)*(9/5)+32), ('kelvin', temp)]) elif option == 'c':    conversions.update([('celsius', temp), ('fahrenheit', temp*(9/5)+32), ('kelvin', temp+273.16)]) elif option == 'f':    conversions.update([('celsius', (temp-32)*(5/9)), ('fahrenheit', temp), ('kelvin', (temp-32)*(5/9)+273.16)]) print(conversions)``` Reply vader33 Unladen Swallow Posts: 3 Threads: 1 Joined: Oct 2016 Reputation: 0 Oct-02-2016, 05:16 AM (Oct-01-2016, 11:35 PM)ichabod801 Wrote: You calculate the output variables, but you don't actually use them in the output. You output tempFormatted, but that is calculated off of temp, which is the original input. You need to calculate tempFormatted from fahrenTemp or celsiusTemp, and then print that. But not that you need to figure out which two calculated variables to output based on the which variable. You are basically already do that when you are calculating them, so you should probably just output them when you calculate them. You're exactly right. I see where I went wrong and made the changes. It took a little doing (this is only my 4th class in Intro to Programming lol), and here's what I came up with:  ```if which =='F':    celsiusTemp = (temp - 32) * 5/9    kelvinTemp = (5/9 * (temp - 32) + 273.15)    tempFormattedC = format(celsiusTemp, '4.1f')    tempFormattedK = format(kelvinTemp, '4.1f')    print('The converted temperature in Kelvin is', tempFormattedK)    print('The converted temperature in Celsius is', tempFormattedC)```I just followed the same format for conversions with Celsius and Kelvin, and everything works as it should. Thanks for your help! Reply

 Possibly Related Threads… Thread Author Replies Views Last Post My first temperature converter TheLowEndTheory 7 289 Oct-18-2020, 04:39 PM Last Post: buran Temperature converter Help (ASAP) Edison_Weng 1 1,340 Apr-16-2018, 01:55 PM Last Post: stranac Using a range and for loop - temp converter rattlerskin 5 7,101 Jan-20-2017, 09:15 PM Last Post: sparkz_alot

Forum Jump:

### User Panel Messages

##### Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020