I wrote this code below for degree conversion but it doesn't work | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I wrote this code below for degree conversion but it doesn't work

Could the problem be that you can't put more than one return in a function ? print("Greetings!\nOptions:\nPress 1 to enter degree in Celsius\nPress 2 to enter degree in Fahrenheit\nPress 3 to enter degree in Kelvin") choice = int(input("Enter your choice")) def converter(num): if choice == 1 : kelvin = num + 273.15 fahrenheit = 1.8 * num + 32 return "The degree you entered is:", kelvin, " in Kelvin and", fahrenheit,"in Fahrenheit" elif choice == 2 : celsius = (num - 32)/1.8 kelvin = celsius + 273.15 return "The degree you entered is:", kelvin, " in Kelvin and", celsius,"in Celsius" elif choice == 3 : celsius = num - 273.15 fahrenheit = (celsius)*1.8 + 32 return "The degree you entered is:", celsius, " in Celsius and", fahrenheit,"in Fahrenheit" elif choice > 3 : return "Option invalid" x = int(input("Enter a number")) print(converter(x))

9th Aug 2020, 9:14 AM
Einstein Shilly shally
Einstein Shilly shally - avatar
3 Answers
+ 2
your returns should be indented in the condition blocks. if xxxxxx: xxxx return xxxx same thing for elif.
9th Aug 2020, 9:34 AM
Bahhaāµ£
Bahhaāµ£ - avatar
+ 1
~ swim ~ Thank you so much
9th Aug 2020, 9:58 AM
Einstein Shilly shally
Einstein Shilly shally - avatar
+ 1
BahhašŸ§ Thank you so much
9th Aug 2020, 9:59 AM
Einstein Shilly shally
Einstein Shilly shally - avatar