Celsius to Fahrenheit code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Celsius to Fahrenheit code

Hey Python pros, Looking for some help figuring this one out . I wm trying to do the challenges at the end of each section in learning Python which have been incredibly helpful. I’m stuck at the Celsius to Fahrenheit conversion problem though! What am I doing wrong? The material doesn’t go much into these things, I’ve looked it over numerous times trying to figure it out. My code is below the # section, the two lines. It keeps failing with an integer issue. I tried putting input there but it terminated so that doesn’t work. Thanks for any tips! celsius = int(input()) def conv(c): #your code goes here c(celsius * 9 / 5 + 32) return c fahrenheit = conv(celsius) print(fahrenheit)

18th Dec 2020, 2:48 AM
CmplXty
7 Answers
+ 11
#This is simple. There was a small mistake in your code. Look at the code below it is working.😊 celsius = int(input()) def conv(c): c=celsius * 9 / 5 + 32 return c fahrenheit = conv(celsius) print(fahrenheit)
18th Dec 2020, 3:02 AM
ツSampriya😘ツ
ツSampriya😘ツ - avatar
+ 2
Actually, the formula is provided on the question page. You just have to copy and paste into the function. https://code.sololearn.com/cmb1VX4r61pq/?ref=app
18th Dec 2020, 5:58 PM
Lam Wei Li
Lam Wei Li - avatar
+ 2
ツSampriyaツ You are supposed to use the c parameter that is parsed into the conv function, instead of using the global variable celsius when inside the function. Because that defeats the purpose of having a c parameter in the first place.
18th Dec 2020, 6:00 PM
Lam Wei Li
Lam Wei Li - avatar
+ 2
Easy code!👌 celsius = int(input()) f = (celsius * 9/5) + 32 print(f)
29th Dec 2020, 6:06 PM
MaryRif
MaryRif - avatar
+ 1
Another thing, maybe change the: celsius = int(input()) to celsius = float(input())
18th Dec 2020, 3:17 AM
noteve
noteve - avatar
0
oh boy do i feel silly lol! thank you, its the little things.. appreciate it!
18th Dec 2020, 3:13 AM
CmplXty
0
import java.util.Scanner; public class Program { //your code goes here static double fahr(int celsius){ double result = (1.8*celsius)+32; return result; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); double c = sc.nextDouble(); int convert= (int)c; System.out.println(fahr(convert)); } }
4th Oct 2023, 2:02 PM
Mohammad Meeran Waseem Siddiqui
Mohammad Meeran Waseem Siddiqui - avatar