0

Trying to do a temperature convertor

I'm trying to do a temperature convertor but I can't understand e fix this error. Can someone help me out with it? Tried to put the inputs out of the If Statement, but it doesn't go on. #The Code scale = input('Which scale do you want to use? ') if scale == c2f: c_f = 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') print(scale)

6th Dec 2022, 10:44 PM
Alexandre Leal de Medeiros Martins Moura
Alexandre Leal de Medeiros Martins Moura - avatar
2 Antworten
+ 3
You need to use quotes as you are comparing the scale input as a string. # Code scale = input('Which scale do you want to use? ') if scale == "c2f": # I added quotes here c_f = float(input('Type the value in Celsius: ')) f = (c_f * 1.8) + 32 print('The temperature is', f, 'Fahrenheit.') elif scale == "f2c": # I added quotes here f_c = float(input('Type the value in Fahrenheit: ')) c = (f_c - 32) / 1.8 print('The temperature is', c, 'Celsius')
6th Dec 2022, 11:08 PM
Pontus Henriksson
Pontus Henriksson - avatar
+ 1
NO WAY, MAN! Little things we don't see. Thanks a lot!
6th Dec 2022, 11:18 PM
Alexandre Leal de Medeiros Martins Moura
Alexandre Leal de Medeiros Martins Moura - avatar