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
Leave A Comment?