Hello everybody, this is a Python program which finds out the smallest and largest number in the list.
Here we use 2 predefined functions min() and max() which check for the smallest and largest number in a list respectively.
You can watch the video on YouTube here
Largest and Smallest in a list – Code Visualization
To find largest and smallest number in a list.
- Read input number asking for length of the list using
- Initialise an empty list
lst = .
- Read each number using a
- In the for loop append each number to the list.
- Now we use predefined function
max()to find the largest element in a list.
- Similarly we use another predefined function
min()to find the smallest element in a list.
lst = 
num = int(input('How many numbers: '))
for n in range(num):
numbers = int(input('Enter number '))
print("Maximum element in the list is :", max(lst), "\nMinimum element in the list is :", min(lst))