Class 11 Programs
- 1.Input a welcome message and display it
- 2.Input two numbers and display the larger/smaller number
- 3.Input three numbers and display the largest / smallest number
- 4.Enter two integers and perform all arithmetic operations
- 5.Generate patterns using nested loop
- 6.Input x and n, print sum of series
- 7.Check perfect number, Armstrong number or palindrome
- 8.Check if number is prime or composite
- 9.Display Fibonacci series terms
- 10.Compute GCD and LCM of two integers
- 11.Count vowels, consonants, uppercase, lowercase in string
- 12.Check palindrome string and convert case
- 13.Find largest/smallest number in list/tuple
- 14.Swap elements at even and odd locations
- 15.Search element in list/tuple
- 16.Find smallest and largest number from list
- 17.Dictionary with student marks above 75
- 18.Menu-driven student dictionary program
- 19.Choose 4 random lucky winners from 100 customers
- 20.String module operations menu
- 21.Friends phone directory dictionary operations
Quick Tips
- • Always test your programs with different inputs
- • Use meaningful variable names
- • Add comments to explain your code
- • Practice regularly to improve coding skills
Find the Largest Among Three Numbers
AIM
To write a Python program that finds the largest among three numbers entered by the user.
ALGORITHM
- Start
- Take three numbers as input from the user
- Compare the first number with the second and third numbers
- If the first number is greater than both the second and third numbers, it is the largest
- Otherwise, compare the second number with the third number
- If the second number is greater than the third number, it is the largest
- Otherwise, the third number is the largest
- Display the largest number
- Stop
PROGRAM
# Python program to find the largest among three numbers
#Write Any One Method
# Taking input from the user
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
# Method 1: Using if-elif-else statements
if num1 >= num2 and num1 >= num3:
largest = num1
elif num2 >= num1 and num2 >= num3:
largest = num2
else:
largest = num3
print("The largest number is:", largest)
# Method 2: Using built-in max() function
# largest = max(num1, num2, num3)
# print("The largest number using max() function is:", largest)OUTPUT
Enter first number: 25
Enter second number: 45
Enter third number: 15
The largest number is: 45.0
Enter first number: 89
Enter second number: 32
Enter third number: 67
The largest number is: 89.0
CONCLUSION
Thus, the given program was successfully executed and the output was verified as per the expected result.
VIVA QUESTIONS
What is the purpose of this program?
The purpose of this program is to find the largest among three numbers entered by the user.
What would happen if we input non-numeric values?
If non-numeric values are entered, the program will raise a ValueError because the float() function cannot convert strings like "abc" to floating-point numbers.
How can we modify this program to find the smallest number?
We can modify the program by changing the comparison operators from >= to <= or by using the min() function instead of max().
What is the advantage of using the max() function?
The max() function provides a more concise and readable solution. It can also handle more than three numbers easily.
How would you modify this program to find the largest among four numbers?
We would need to add another input for the fourth number and either extend the if-elif-else statements or simply add the fourth number to the max() function.
Related Resources
- Python Conditional Statements
- Python Operators Tutorial
- Python Input/Output
- Practice MCQs on Conditionals
Need Help?
Join our tuition classes for personalized guidance and doubt clearing.
Register for Classes →