Programming Examples

Python Program to find the successor and predecessor of the largest element in list


Python Program to find the successor and predecessor of the largest element in list

Solution

mylist=eval(input("Enter any List : "))
m=max(mylist)
mi=mylist.index(m)
#print(m," -> ",mi)
if mi>0:
    print("Predecessor of Largest No. ",mylist[mi-1])
else:
    print("No Predecessor Exist")

if mi<len(mylist)-1:
    print("Successor of Largest No. ",mylist[mi+1])
else:
    print("No Successor Exist")
Output


Enter any List : [1,2,3,5,2,1]

Predecessor of Largest No.  3

Successor of Largest No.  2

>>> 

======================

Enter any List : [1,2,3,4]

Predecessor of Largest No.  3

No Successor Exist

>>> 

======================

Enter any List : [4,3,2,1]

No Predecessor Exist

Successor of Largest No.  3

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz