Here,We are going to write python program to input list of numbers and find the smallest and largest number from the list.This python program allows user to enter the length of a List. We can use For Loop to add numbers to the list. With the help of min and max functions in python,we can find out the the smallest and largest numbers or minimum and maximum values in a list

Python program to find smallest and largest number from list using for loop

# Python Program to find Largest and Smallest Number in a List 

nums = []
n = int(input("Enter the Total Number of List Elements: "))
for i in range(1, n + 1):
    value = int(input("Enter the Value of %d Element : " %i))
    nums.append(value)

print("The Smallest Element in this List is : ", min(nums))
print("The Largest Element in this List is : ", max(nums))


Output

Enter the Total Number of List Elements: 5
Enter the Value of 1 Element : 45
Enter the Value of 2 Element : 77
Enter the Value of 3 Element : 99
Enter the Value of 4 Element : 88
Enter the Value of 5 Element : 22
The Smallest Element in this List is :  22
The Largest Element in this List is :  99

Check our other python programs too

<

Leave a Reply

Your email address will not be published.