Sunday, March 3, 2019

Maximum & Minimum in List using Loop & In-built Function - Python3

list1 = []
len_list1 = int(input("Enter the number of items to enter into the list1: "))
for i in range(len_list1):
    new = int(input("Enter the item value: "))
    list1.append(new)

print("Using inbuilt function:-")
print("Maximum : %d \nMinimum : %d"%(max(list1),min(list1)))

print("Using for loop:-")
max1 = list1[0]
min1 = list1[0]

for i in list1:
    if i > max1:
        max1 = i

    if i < min1:
        min1 = i

print("Maximum : %d \nMinimum : %d"%(max1,min1))


ScreenShot:

No comments:

Post a Comment