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 numberslist1 = [10, 20, 4, 45, 99]# sorting the listlist1.sort()# printing the first elementprint("Smallest element is:", *list1[:1]) |
Output:
smallest element is: 4
Solutie
Method 2 : Using min() method
# list of numberslist1 = [10, 20, 1, 45, 99]# printing the maximum elementprint("Smallest element is:", min(list1)) |
Output:
Smallest element is: 1
Leave A Comment?