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

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 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 Best Website and Software Company in Allahabad