5. Problem to find minimum and maximum elements from a list

In this program, we will take a user input as a list and find the minimum and maximum elements from it with the help of the below-given steps.

Table of Contents

Minimum and maximum element in list:

Method 1 : Sorting and indexing

Steps to solve the program
  1. Take a list as input.
  2. Sort the list using Sort().
  3. Print the maximum value i.e. element with -1 index.
  4. Print the minimum value i.e. element with 0 index.
				
					#Input list
list1 = [23,56,12,89]

#Sorting list
list1.sort()

#Printing output
print("Smallest number: ", list1[0])
print("Largest number: ", list1[-1])
				
			

Output :

				
					Smallest number:  12
Largest number:  89
				
			

Minimum and maximum element in list:

Method 2 : Using in-built function

Steps to solve the program
  1. Take a list as input.
  2. Print the maximum value using max().
  3. Print the minimum value using min().
				
					#Input list
list1 = [23,56,12,89]

#Printing output
print("Smallest number: ", min(list1))
print("Largest number: ", max(list1))
				
			

Output :

				
					Smallest number:  12
Largest number:  89
				
			

Related Articles

Product of all elements

 Differentiate even and odd elements

Leave a Comment