jeudi 23 septembre 2021

Program prints the else condition even when the if statements are true in Python

I'd like to convert my Celsius temp to fahrenhite and vice versa. This is the code I've given:

temperature=int(input('what is the temperature? '))

type=input('is it in celsius or fahrenheit: ')

if temperature == 'celsius':

converted_temp = (temperature*9/5)+32 

print("The converted temp in fahrenheitis: ",converted_temp) 

elif temperature == 'fahrenheit':

converted_temp = (temperature-32)*5/9 

print('The converted temperature in celsius is:',converted_temp) 

else:

print("SORRY! Enter either Celsius or Fahrenheit") 

Aucun commentaire:

Enregistrer un commentaire