0

Can anyone explain how this code works?

celsius = int(input()) def conv(c): f= ((9/5)* c) + 32 #how it understands that it's celsius, we just put c return f fahrenheit = conv(celsius) #what is conv(celsius), we used conv(c) print(fahrenheit)

5th Nov 2022, 12:36 AM
Arsen Sadikyan
2 Answers
+ 2
The key concept here is scope. You have a main routine and a function called "conv". Each routine, function, method, etc., is an independent scope. That means a different set of variables and objects. One scope doesn't know about the others. Variable "c" doesn't exist in the main routine, and variable "celsius" doesn't exist in function "conv". You defined "conv" function with a parameter "c", which becomes a variable inside the function scope, used to calculate the returned value. When you call function "conv" with "celsius" as an argument, the main routine sends the value of "celsius", and the function stores the received value in its variable "c".
5th Nov 2022, 1:11 AM
Emerson Prado
Emerson Prado - avatar
0
Oh I got it now. Thank you very much.
5th Nov 2022, 1:13 AM
Arsen Sadikyan