Ask Question
19 September, 16:27

We will pass you 2 inputsan list of numbersa number, N, to look forYour job is to loop through the list and find the number specified in the second input. Output the list element index where you find the number. If N is not found in the list, output - 1. Tip: Remember the break statement? It exits the loop. You can (but don't have to) use this.# Get our input from the command lineimport sysN = int (sys. argv[2]) # Convert the list of strings into integersnumbers = []for i in sys. argv[1]. split (",") : if (i. isdigit ()) : numbers. append (int (i)) # numbers now contains the list of integers# Write your code below

+1
Answers (1)
  1. 19 September, 18:51
    0
    The Python code is given below

    Explanation:

    # Get our input from the command line

    import sys

    N = int (sys. argv[2])

    # Convert the list of strings into integers

    numbers = []

    for i in sys. argv[1]. split (","):

    if (i. isdigit ()):

    numbers. append (int (i))

    # numbers now contains the list of integers

    f = False

    #Use for loop upto len (numbers)

    for i in range (0, len (numbers)):

    #Use "if" loop to check

    if numbers[i] = = N:

    #Assign "True" to "f"

    f = True

    #Display "i"

    print (i)

    break

    #Check "if" loop by assigning "false" to "f"

    if f==False:

    #Print "-1"

    print ("-1")
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “We will pass you 2 inputsan list of numbersa number, N, to look forYour job is to loop through the list and find the number specified in ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers