# Python Program to Find Smallest Number in a List

« Previous Program Next Program »

• Find smallest number in a list of 10 numbers
• Find smallest number in a list of n numbers
• Find smallest number in a list using min() method
• Find smallest number in a list using sort() method and then indexing

## Find Smallest Number in List of 10 Numbers

The question is, write a Python program to find smallest number in a list without using any predefined method. Here is its answer:

```nums = []
print("Enter 10 Elements (Numbers) for List: ")
for i in range(10):
nums.append(int(input()))
small = nums
for i in range(10):
if small>nums[i]:
small = nums[i]
print("\nSmallest Number is: ")
print(small)```

Here is the initial output of this program's sample run:

Now supply the input say 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 as ten numbers to find and print the smallest from the given list of numbers as shown in the snapshot of sample's run given below:

## Find Smallest Number in List of n Numbers

This is the modified version of previous program. This program allows user to define the size of list before entering elements for list. The end used in this program to skip insertion of an automatic newline. The str() converts any type of value to a string type.

```nums = []
print(end="Enter the Size: ")
numsSize = int(input())
print(end="Enter " +str(numsSize)+ " Numbers: ")
for i in range(numsSize):
nums.append(int(input()))
small = nums
for i in range(numsSize):
if small>nums[i]:
small = nums[i]
print("\nSmallest Number = " + str(small))```

Here is its sample run with user input, 5 as size and 5, 4, 3, 1, 2 as five elements:

## Find Smallest Number in List using min()

The question is, write a Python program to find smallest number in list using min(). Here is its answer:

```nums = list()
print(end="Enter the Size: ")
numsSize = int(input())
print(end="Enter " +str(numsSize)+ " Numbers: ")
for i in range(numsSize):
nums.append(int(input()))

print("\nSmallest Number = " + str(min(nums)))```

## Find Smallest Number in List using sort()

This program uses sort() method to sort the list in ascending order (by default) and then by using list indexing, I've printed the smallest number in the given list like shown in the program given below:

```nums = list()
print(end="Enter the Size: ")
numsSize = int(input())
print(end="Enter " +str(numsSize)+ " Numbers: ")
for i in range(numsSize):
nums.append(int(input()))
nums.sort()
print("\nSmallest Number = " + str(nums))```

Python Online Test

« Previous Program Next Program »