0

Temperature Converter in python

I'm trying to do a simple converter, but I'm stucked in one particular area. If someone knows how I can solve this, I appreciate. while True: scale = input('Which scale do you want to use? ') options = input('Do you want to change scale? (y/n)') if scale == 'c2f': c2f = float(input('Type the value in Celsius: ')) f = (c2f * 1.8) + 32 print('The temperature is', f, 'Fahrenheit.') elif scale == 'f2c': f2c = float(input('Type the value in Fahrenheit: ')) c = (f2c - 32) / 1.8 print('The temperature is', c, 'Celsius') I'm trying to fit this "options" var to let the user decide if it will continue or stop the program. How can I fit this in? Thanks in advance!

7th Dec 2022, 9:57 PM
Alexandre Leal de Medeiros Martins Moura
Alexandre Leal de Medeiros Martins Moura - avatar
4 Answers
+ 5
Alexandre Leal de Medeiros Martins Moura , > a possible solution would be to place the question / input for changing the scale just at the end of the code. > it would also make sense to add an input option for terminating the program. this could be 'x'. see your code with the amendments in the attached file: https://code.sololearn.com/c67Oc6IniP9a/?ref=app
8th Dec 2022, 8:34 PM
Lothar
Lothar - avatar
+ 6
Alexandre Leal de Medeiros Martins Moura , i have updated the code file in my previous post. it gives you the ability to run the code in a visual debugger.
9th Dec 2022, 6:53 PM
Lothar
Lothar - avatar
+ 1
Thanks, Lothar! Can you explain me what was the logic for the options. I think I got it right, but there's something that is not fitting in my head.
8th Dec 2022, 10:25 PM
Alexandre Leal de Medeiros Martins Moura
Alexandre Leal de Medeiros Martins Moura - avatar
0
scale = input('Which scale do you want to use? '); options = input('Do you want to change scale? (y/n)'); if options == 'n': print("You don't want to change scale") exit() if scale == 'c2f': c2f = float(input('Type the value in Celsius: ')) f = (c2f * 1.8) + 32 print('The temperature is', f, 'Fahrenheit.') elif scale == 'f2c': f2c = float(input('Type the value in Fahrenheit: ')) c = (f2c - 32) / 1.8 print('The temperature is', c, 'Celsius')
7th Dec 2022, 11:32 PM
Minhaj Azeem
Minhaj Azeem - avatar