Input: a = 10, b = 4, c = 9 Output: 10 Input: a = 5, b = 12, c = 10 Output: 12
Python Program to Find Maximum of Three Using if-else statement.
- If a is greater than or equal to b and c, set largest to a.
- Else if b is greater than or equal to a and c, set largest to b.
- Else, set largest to c.
# Python program find largest of three number # Step 1: Input three numbers num1 = float(input("Enter the first number: ")) num2 = float(input("Enter the second number: ")) num3 = float(input("Enter the third number: ")) # Step 2: Compare using if-else statements if num1 >= num2 and num1 >= num3: largest = num1 elif num2 >= num1 and num2 >= num3: largest = num2 else: largest = num3 # Step 3: Output the result print(f"The largest number is: {largest}")
Enter the first number: 10 Enter the second number: 15 Enter the third number: 8 The largest number is: 15.0
Python Program to Find Maximum of Three Numbers Using max() Function.
- STEP 1: Take three inputs a, b, and c from the user.
- STEP 2: Use the max() function to find the maximum among the three numbers. Assign the result to largest.
- STEP 3: Print the result, indicating the largest number.
# Python program find largest of three number using max() # Input three numbers num1 = float(input("Enter the first number: ")) num2 = float(input("Enter the second number: ")) num3 = float(input("Enter the third number: ")) # Use the max() function largest = max(num1, num2, num3) # Output the result print(f"The largest number is: {largest}")
Enter the first number: 12 Enter the second number: 10 Enter the third number: 15 The largest number is: 15.0