Python Programs | IT Developer
IT Developer

Python Programs



Share with a Friend

Python Programs - Functions

Function to find the maximum of three numbers - Python Program

Example 1 :

def max_of_three(a, b, c): """Return the largest of three numbers.""" return max(a, b, c) print(max_of_three(10, 25, 15))

Output

 
OUTPUT  :
25
 

Example 2 : Advanced Program

def find_maximum_of_three(num1, num2, num3): """ Finds the maximum of three given numbers. Args: num1: The first number. num2: The second number. num3: The third number. Returns: The largest among the three numbers. """ return max(num1, num2, num3) # Example Usage and Output number1 = int(input("Enter First Number : ")) number2 = int(input("Enter Second Number : ")) number3 = int(input("Enter Third Number : ")) maximum_number = find_maximum_of_three(number1, number2, number3) print(f"The maximum of {number1}, {number2}, and {number3} is: {maximum_number}") # Another example print(f"The maximum of 7, 9, and 30 is: {find_maximum_of_three(7, 9, 30)}")

Output

 
OUTPUT  :
Enter First Number : 10
Enter Second Number : 25
Enter Third Number : 15
The maximum of 10, 25, and 15 is: 25
The maximum of 7, 9, and 30 is: 30

Explanation:

The find_maximum_of_three function takes three arguments: num1num2, and num3. Inside the function, the max() built-in function is directly used. The max() function can accept multiple arguments and returns the largest among them. This makes it a highly efficient and readable way to find the maximum of several numbers. The function then returns this maximum value.