smallest element in the list python | without using built-in function

Python Program to get list size n and n elements of list, then find the smallest element among those elements.

Sample Input 1:

5 5 7 9 3 1

Sample Output 1:


Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

#write your code here

Program or Solution

l=list(map(int,input("Enter array elements:").split(" ")))
for i in range(1,len(l)):



Program Explanation

Input: To get list of numbers seprated by space, use split(" ") method.

Split() method splits the numbers as seprate elements.

By default this methods are considered as string, since input() method returs string. Use map() function to convert all elements as integer and store it in list.

Process: Initially assign the element located at 0 to min using min = l[0].

using for loop visit each location serially from 1 to len(l)-1. if the element located in any position is lesser than min, then assign the element as min by using min = l[i] finally min holds the minimum value in the list.