+ 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
3 Réponses
+ 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😅
+ 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.
+ 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)