In the last post about the python, I have shown how you can create the array by supplying user input values. Now, in this code I am gonna show how you can print the index number of certain value that is supplied by the user. For this I create my own custom array just for learning. Here's the code:
from array import *
MyArray=array('i',[23,45,33,21,87,56,10])
Value=int(input("Enter the value whose index is to be found: "))
i=0
for e in MyArray:
if e==Value:
print(i)
i=i+1
#Another method to find the index
print(MyArray.index(Value))
The output of this code is as follows:
You can also run this code in the online python compiler here.