Celsius to Fahrenheit code | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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