Write a python program to find maximum of a list of numbers

 Here first we take input of list of the numbers then simply by using max() function we can easily find the maximum number between list of the numbers . And we can also find maximum without using max()  .For this first we assume that first element of the list is maximum and compare it with all the numbers one by one and if it is less than any number then max_number  is equal to that number. By using this we can simply find the maximum among list of numbers. So let’s start with the coding.

method 1:-

In this method we simply use max() function which is inbuild function . first we take input a number (number of element in the list ) then list of the numbers . After that by using max() we can simply find the maximum number among the list of the numbers.

Code:-

n=int(input(“Enter number of element in list”))
mylist=[]
print(“Enter elements of the list”)
for _ in range(n):
a=int(input())
mylist.append(a)
maximum=max(mylist)
print(“Maximum of the list is :”,maximum)

Output:-

Enter number of element in list 5
Enter elements of the list
12
32
45
67
87
Maximum of the list is : 87

Method 2:-

In this method we will find the maximum without using inbuilt function . For this first we assume first element of the list as a maximum number and store it in max_number and compare it with all the elements and if max_number is less than any number then update max_number by this number. 

Code:-

n=int(input(“Enter number of element in list”))
mylist=[]
print(“Enter elements of the list”)
for _ in range(n):
a=int(input())
mylist.append(a)
maximum=mylist[0]
for i in mylist:
if maximum<i:
maximum=i
print(“Maximum of the list is :”,maximum)

Output:-

Enter number of element in list 5
Enter elements of the list
12
32
45
67
87
Maximum of the list is : 87



Recommended Post:-

         MCQs:-

Leave a Reply

Your email address will not be published.