How To Find the Smallest Number in a List
This is a Python Program to find the Smallest number in a list.
The program takes a list and prints the smallest number in the list.
li = []
n = int(input("Enter the number of elements: "))
for i in range(1, n+1):
elem = int(input("Enter the elements: "))
li.append(elem)
li.sort()
print("The sorted list: ", li)
print("The smallest value of this list: ",li[0])
li = []
n = int(input("Enter the number of elements: "))
for i in range(1, n+1):
elem = int(input("Enter the elements: "))
li.append(elem)
li.sort()
print("The sorted list: ", li)
print("The smallest value of this list: ",li[0])
Enter the number of elements: 4
Enter the elements: 36
Enter the elements: 14
Enter the elements: 52
Enter the elements: 78
The sorted list: [14, 36, 52, 78]
The smallest value of this list: 14
li = []
n = int(input("Enter the number of elements: "))
for i in range(1, n+1):
elem = int(input("Enter the elements: "))
li.append(elem)
li.sort()
print("The sorted list: ", li)
print("The smallest value of this list: ",li[0])
Enter the number of elements: 10
Enter the elements: -7
Enter the elements: 15
Enter the elements: 86
Enter the elements: -3
Enter the elements: 0
Enter the elements: 49
Enter the elements: 78
Enter the elements: 2
Enter the elements: -3
Enter the elements: 33
The sorted list: [-7, -3, -3, 0, 2, 15, 33, 49, 78, 86]
The smallest value of this list: -7
li = []
n = int(input("Enter the number of elements: "))
for i in range(1, n+1):
elem = int(input("Enter the elements: "))
li.append(elem)
li.sort()
print("The sorted list: ", li)
print("The smallest value of this list: ",li[0])
Enter the number of elements: 5
Enter the elements: -4
Enter the elements: -3
Enter the elements: -2
Enter the elements: -1
Enter the elements: 0
The sorted list: [-4, -3, -2, -1, 0]
The smallest value of this list: -4
Jubayer Hossain
Please share your tips or tricks for solving this problem in a better way! Happy Coding!