In this program, we will learn how to find the smallest number in a list using Python Programming language.
For example: If the list is [27, 30, 15, 47, 71], then this program will compute and display the smallest number in the list which is 15 for this case.
We will find the smallest number in the list using following methods:
- Using min() function
- Using Sort() function
- Using User Input
So, without further ado, let’s begin this tutorial.
Python Program to Find Smallest Number in a List
# Python Program to Find Smallest Number in a List # Given list of numbers a = [50, 44, 72, 22, 48, 60] # Finding smallest number smallest = min(a) # Displaying output print("Smallest number in the list is: ", smallest)
Output
Smallest number in the list is: 22
How Does This Program Work ?
# Given list of numbers a = [50, 44, 72, 22, 48, 60]
Here, in this program we have defined a list which contains 6 elements.
# Finding smallest number smallest = min(a)
Now, we used min() function to compute the smallest number in the list. min() function take a list as argument and returns the minimum element of the list.
Python Program to Find Smallest Number in a List Using Sort() Method
# Python Program to Find Smallest Number in a List Using Sort() Function # Given list list = [17, 25, 38, 8, 50, 27, 36, 12] # Sorting the list list.sort() # Finding smallest number smallest = list[0] # Displaying output print("Smallest number in the list is: ", smallest)
Output
Smallest number in the list is: 8
Python Program to Find Smallest Number in a List With User Input
# Python Program to Find Smallest Number in a List With User Input a = [] # Enter total number of elements count = int(input("Enter total number of elements: ")) # Getting elements of the list for i in range(count): num = int(input("Enter number: ")) a.append(num) # Finding smallest element in the list smallest = min(a) # Displaying output print("Smallest number in the list is: ", smallest)
Output
Enter total number of elements: 5
Enter number: 12
Enter number: 17
Enter number: 5
Enter number: 3
Enter number: 25
Smallest number in the list is: 3
Conclusion
I hope after going through this post, you understand how to find the smallest number in a list using Python Programming language.
If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to help you.
Also Read: