Movatterモバイル変換


[0]ホーム

URL:


Skip to content
July 19, 2025
Latest
Home »Python program to find the largest and smallest number in a list
Python program to find the largest and smallest number in a list
Python program to find the largest and smallest number in a listPython program to find the largest and smallest number in a list

Hello everybody, welcome back toprogramminginpython.com. Here in this post, I am going to discuss a Python program that finds out the smallest and largest number on thelist.

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

Master the basics of data analysis in Python. Expand your skillset by learning scientific computing with numpy.

Take the course on Introduction to Python onDataCamp herehttps://bit.ly/datacamp-intro-to-python

 

You can watch the video on YouTubehere

Program on GitHub

Largest and Smallest in a list – Code Visualization

Task :

To find the largest and smallest number in a list.

Approach :

  • Read the input number asking for the length of the list usinginput() orraw_input().
  • Initialize an empty listlst = [].
  • Read each number using afor loop.
  • In the for loop append each item to the list,lst.append().
  • Now we use a predefined functionmax() to find the largest element in a list.
  • Similarly, we use another predefined functionmin() to find the smallest element in a list.

Program on GitHub

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 a List
The smallest and Largest element in a List

Program on GitHub

That is for the post, here I have found the largest and the smallest element in a given list, usingmax() andmin() built-in functions of the list which give us the maximum and minimum element from a given list.

Course Suggestion

Want to learn Python with strong fundamentals? If yes, I strongly suggest you take the course below.
Course:Fundamentals of Programming in Python

 

Online Python Compiler

Leave a ReplyCancel reply

Your email address will not be published.Required fields are marked*

Special Offer

Subscribe to our newsletter!

Great Deals

Ads

Categories


[8]ページ先頭

©2009-2025 Movatter.jp