Write a Python program to get the smallest number from a list


This program is a Python script that finds the smallest number in a given list of numbers. The list of numbers is defined at the beginning of the program as "a" with the values [51,7,10,34,2,8].

The program uses a for loop to iterate through each element in the list. The first element of the list is set as the initial value for the variable "min_num". As the for loop iterates through each element in the list, it checks if the current element is less than the current value of "min_num". If it is, it updates "min_num" to the current element.

After the for loop completes, the final value of "min_num" is the smallest number in the list and the program prints out this value as "Smallest Number :" followed by the smallest number. This program has a commented out line that uses built-in min() function of python to achieve the same thing.

Source Code

a=[51,7,10,34,2,8]
"""
print("Smallest Number :",min(a))
"""
min_num = a[0]
for i in a:
	if i < min_num:
		min_num = i
print("Smallest Number :",min_num)
 

Output

Smallest Number :2

Example Programs