In: Computer Science
Write a Python function that will return the index of an element in a list.1- The function will receive a list of at least 5 numbers as a single argument when the function is called. 2. The function will ask the user to input a number and will find and return the index of that number in the list.3. If the number is not an element of the list, the function returns the string "unknown."
Thanks for the question. Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks! =========================================================================== def getIndex(lst): # The function will ask the user to input a number number = int(input('Enter a number: ')) # iterate over each element in the list for i in range(len(lst)): # if the current index number matches user number if lst[i] == number: return i # return the index # if there are no matches return 'unknown' return 'unknown' def main(): lst = [1, 2, 3, 45, 6] index = getIndex(lst) print('Index:', index) main()
===================================================================