+ 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)
7 Respuestas
+ 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)
+ 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
+ 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.
+ 2
Easy code!👌
celsius = int(input())
f = (celsius * 9/5) + 32
print(f)
+ 1
Another thing, maybe change the:
celsius = int(input())
to
celsius = float(input())
0
oh boy do i feel silly lol! thank you, its the little things.. appreciate it!
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));
}
}