Answer to Question #315281 in Python for sabiha1

Question #315281

index of last occurrence


write s program to print the index of the last occurence of the given number N in the list.


input


the first line of input will contain space separated integers.

the second line of input will contain an integer N


output


the output should be the index of the last occurence of the number N


explanation


for example, if the given list of numbers and N are


2 4 5 6 7 8 2 4 5 2 3 8 2


number 2 present at index locations 0, 6, 9, as the last occurence, is at index 9. so the output should be 9.


sample input 1

2 4 5 6 7 8 2 4 5 2 3 8 2


sample output 1

9


sample input 2

65 87 96 31 32 86 57 69 20 42 32 32 32


sample output 2

11


1
Expert's answer
2022-03-21T12:35:34-0400
a = [int(i) for i in input("Enter list of numbers: ").split()]
b = int(input("Search number: "))
index = 0
for i in range(len(a)):
    if a[i] == b:
        index = i
print("Index of Last Occurrence: ", index)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS