Code Explanation:
Lambda Function:
lambda c: (c * 9/5) + 32 defines an anonymous function (lambda function) that takes a single argument c.
The body of the function is (c * 9/5) + 32. This formula converts a temperature from Celsius to Fahrenheit.
Assigning the Function:
c_ to _f = lambda c: (c * 9/5) + 32 assigns the lambda function to the variable c_to_f.
Now, c_to_f can be used as a regular function to convert temperatures.
Calling the Function:
result = c_to_f(25) calls the c_to_f function with the argument 25 (25 degrees Celsius).
Inside the function, the formula (25 * 9/5) + 32 is evaluated:
25×9/5=45
45+32=77
So, the function returns 77.
Printing the Result:
print(result) outputs the value of result to the console, which is 77.
Output:
The program prints:
77
This shows that 25 degrees Celsius is equivalent to 77 degrees Fahrenheit.
0 Comments:
Post a Comment