Python program to find smallest number in a list

Configurare noua (How To)

Situatie

Given a list of numbers, the task is to write a Python program to find the smallest number in given list.

Examples:

Input : list1 = [10, 20, 4]
Output : 4

Input : list2 = [20, 10, 20, 1, 100]
Output : 1

Backup

# list of numbers
list1 = [10, 20, 4, 45, 99]
# sorting the list
list1.sort()
# printing the first element
print("Smallest element is:", *list1[:1])

Output: 

smallest element is: 4

Solutie

Method 2 : Using min() method

# list of numbers
list1 = [10, 20, 1, 45, 99]
# printing the maximum element
print("Smallest element is:", min(list1))

Output: 

Smallest element is: 1

Tip solutie

Permanent

Voteaza

(11 din 21 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?