Python program to find the largest and smallest number in a list

Python program to find the largest and smallest number in a list

Hello everybody, this is a Python program which finds out the smallest and largest number in the list.

Image for postSmallest and Largest number in list ? programminginpython.com

Here we use 2 predefined functions min() and max() which check for the smallest and largest number in a list respectively.

Task :

To find largest and smallest number in a list.

Approach :

  • Read input number asking for length of the list using input() or raw_input().
  • Initialise an empty list lst = .
  • Read each number using a for loop.
  • 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.

Program :

lst = num = int(input(‘How many numbers: ‘))for n in range(num): numbers = int(input(‘Enter number ‘)) lst.append(numbers)print(“Maximum element in the list is :”, max(lst), “nMinimum element in the list is :”, min(lst))

Output :

Smallest and Largest element in list - programminginpython.comSmallest and Largest number in list ? programminginpython.com

Post: http://programminginpython.com/python-program-largest-smallest-number-list/

Python Programming – Largest and Smallest number in a list

Hello everybody, this is a Python program which finds out the smallest and largest number in the list. Here we use 2?

programminginpython.com

GitHub: https://github.com/avinashn/programminginpython.com/blob/master/largest_smallest_list.py

avinashn/programminginpython.com

This repo consists code of all the programs discussed at programminginpython.com website

github.com

4

No Responses

Write a response