Python program to find smallest number in a listGiven a list of numbers, the task is to write a Python program to find the smallest number in given list. Show Method 1 : Sort the list in ascending order and print the first element in the list. Python3
Output: smallest element is: 4Method 2 : Using min() method Python3
Output: Smallest element is: 1 Method 3 : Find min list element on inputs provided by user. Python3
Output: Method 4: Find the smallest element in list. Python3
Input: List: 23,-1,45,22.6,78,100,-5Output: The list is ['23', '-1', '45', '22.6', '78', '100','-5'] The smallest element in the list is -5
Article Tags :
Python Python Programs
Python list-programs python-list Practice Tags :
python-list Python program to print odd numbers in a ListGiven a list of numbers, write a Python program to print all odd numbers in given list. Example: Input: list1 = [2, 7, 5, 64, 14] Output: [7, 5] Input: list2 = [12, 14, 95, 3, 73] Output: [95, 3, 73]
Article Tags :
Python Python Programs School Programming
Python list-programs python-list Practice Tags :
python-list Smallest odd numberIn this program, we need to find out the smallest odd number from the given integer number.
Let us understand the concept of the above problem with the help of the below-mentioned examples: Example 1: If we have given a number ' n ', n = 12345, we need to find the smallest odd number. n = 12345 The number of odd numbers is: 1, 3, 5 But among the list of odd numbers, we require to find the smallest odd number, Therefore the output will be 1. Example 2: If we have given a number ' n ', n = 8745329, we need to find the smallest odd number. n = 874532 The number of odd numbers is: 7, 5, 3, 9 But among the list of odd numbers, we require to find the smallest odd number, Therefore the output will be 3. Example 3: If we have given a number ' n ', n = 750, we need to find the smallest odd number. n = 750 The number of odd numbers is: 7, 5 But among the list of odd numbers, we require to find the smallest odd number, Therefore the output will be 7. Example 4: If we have given a number ' n ', n = 220, we need to find the smallest odd number. n = 220 The number of odd numbers is: none But among the list of odd numbers, we require to find the smallest odd number, Therefore the output will be -1. Here, -1 indicates that no smallest odd number is found from the given number, which means that all the numbers present are even. Example 5: If we have given a number ' n ', n = 97998, we need to find the smallest odd number. n = 97998 The number of odd numbers is: 9, 7 But among the list of odd numbers, we require to find the smallest odd number, Therefore the output will be 7. Example 6: If we have given a number ' n ', n = 6620, we need to find the smallest odd number. n = 6620 The number of odd numbers is: none But among the list of odd numbers, we require to find the smallest odd number, Therefore the output will be -1. Here, -1 indicates that no smallest odd number is found from the given number, which means that all the numbers present are even. With the help of the above examples, we have clearly understood what we need to do in this problem. Let us implement the above problem to find the smallest odd number using the approach mentioned below. Python Program to find the Smallest Number in a List Example 1The Python min function returns the minimum value in a List. # Python Program to find Smallest Number in a List a = [10, 50, 60, 80, 20, 15] print("The Smallest Element in this List is : ", min(a))Python smallest list number output The Smallest Element in this List is : 10Python: Get the smallest number from a listLast update on June 23 2021 14:09:45 (UTC/GMT +8 hours) |