def find_largest(a, b, c):
"""This function takes three numbers as arguments and returns the largest number."""
return max(a, b, c)
result = find_largest(10, 25, 8)
print("The largest number is:", result)
#source code --> clcoding.com
Code Explanation:
Function Definition
def find_largest(a, b, c):
def defines a function.
find_largest is the function name.
It takes three parameters: a, b, c, which represent the three numbers.
Docstring (Optional but Recommended)
"""This function takes three numbers as arguments and returns the largest number."""
Describes what the function does.
Helps in documentation and debugging.
Using max() Function
return max(a, b, c)
max(a, b, c) returns the largest of the three numbers.
Example calculations:
max(10, 25, 8) → 25
max(45, 12, 30) → 45
Calling the Function
result = find_largest(10, 25, 8)
Calls the function with numbers 10, 25, and 8.
Stores the largest number in result.
Printing the Result
print("The largest number is:", result)
Displays:
The largest number is: 25
0 Comments:
Post a Comment