Friday, 12 January 2018

Python Program to Print Largest Even and Largest Odd Number in a List

Source Code :

n = int(input("Enter the no of elements in the list :"))
b=[]
for i in range(0,n):
    a=int(input("Enter elements :"))
    b.append(a)
c=[]
d=[]

for i in b:
    if (i%2==0):
        c.append(i)
    else :
        d.append(i)
c.sort()
d.sort()
count1=0
count2=0
for k in c:
    count1=count1+1
for j in d:
    count2=count2+1
print("Largest even no is : ",c[count1-1])

print("Largest odd no is :", d[count2-1])

Output :

Enter the no of elements in the list :7
Enter elements : 9
Enter elements : 17
Enter elements : 2
Enter elements : 89
Enter elements : 40
Enter elements : 102
Enter elements : 101
Largest even no is :  102
Largest odd no is : 101

No comments:

Post a Comment