+ 3

How to convert temperature from Celsius to Fahrenheit in python

celsius = int(input()) def conv(c): #your code goes here fahrenheit = (c *9/5) + 32 return fahrenheit fahrenheit = conv(celsius) print(fahrenheit) #I strugle a lot bc of this code and all was bc i type wrong celsius for example instead "Celsius" I type "Celcius" and this little mistake gave me hours of recode #Edit: the code is working

26th Jan 2021, 2:06 AM
Nicky
Nicky - avatar
3 ответов
+ 6
def conv(c): fahrenheit = (c * 9/5) + 32 return fahrenheit "c" is your function parameter, so you should use that variable instead of the global variable "celsius". When you pass an argument as parameter to a function, you should use that parameter name instead.. ::btw same here Im struggling between Celcius and Celsius😅
26th Jan 2021, 2:10 AM
noteve
noteve - avatar
+ 3
Nicky Yes, it should work even if you used the global scope variable "Celsius" as it was declared before the function. (You can even call the function without the parameter and it would still work) Though, this may not be important with this problem, but using global variables instead of parameters (that have been passed) inside the function is a bad practice and often cause bugs.
26th Jan 2021, 2:20 AM
noteve
noteve - avatar
+ 1
hahaha ik ik btw I Try using (c) but that don't work at the time so I just try with celsius and works perfectly. edit: I tried again with (c) and works too so that means that my problem was “Celcius” (the mistyping)
26th Jan 2021, 2:13 AM
Nicky
Nicky - avatar