Example HTML page

Python program to find the largest and smallest numbers in a list.

lst = [ ]
num = int(input("How many elements:"))
for n in range(num):
    numbers = int(input("Enter number: "))
    lst.append(numbers)
print("Largest number in a list:", max(lst))
print("Smallest number in a list:",min(lst))

lst = [ ] created empty list.

append() method adds a single item to the existing list. It does not return a new list, rather it modifies the original list.

min() is used to find smallest element in the list and max() is used to find the largest element in the list.

How many elements:5
Enter number: 10
Enter number: 5
Enter number: 4
Enter number: 20
Enter number: 25
Largest number in a list: 25
Smallest number in a list: 4

 

 

 

Example HTML page

Leave a Reply

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

Pin It on Pinterest