1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Art [367]
3 years ago
12

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 spec

ified 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
Computers and Technology
1 answer:
Montano1993 [528]3 years ago
4 0

Answer:

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")

You might be interested in
1D Array Assignment Outcome: Student will demonstrate the ability to use a one-dimensional array. Student will demonstrate the a
sukhopar [10]

Answer:

Program to this question as follows:

program:

import java.util.*; //import package for user input

public class Main  //defining class  

{

public static void main(String[] as)//defining main function

{//defining integer array

int [] num = new int[113];  

boolean find_in = false; //defining boolean variable

int [] counts = new int[101];//defining integer array

int y, tem = 0, counter = 0,in=0,x,find; //defining integer variable

Scanner ox= new Scanner(System.in); //creating Scanner class Object

while(counter <= 112) //loop to check condition

{

num[counter++] = generateRandomNumber(); //using array to hold random function value.  

}

System.out.println("The array:"); //message

for(x = 0; x < 112; x++) // loop to count the value

{

if(x != 0 && x % 9 == 0) // if block to chek value

System.out.println(); // print  

else

System.out.print(num[x] + " "); // print array

}

// sort in ascending order

Arrays.sort(num); //using sort method

System.out.print("\n\nThe array in sorted order:"); // print value

for( x = 0; x < num.length; x++) // loop uses if block to check value is divisiable by 9  

{

if(x % 9 == 0) //check condition  

System.out.println(); // print  

else

System.out.print(num[x] + " "); // print array

}

// search for a number

System.out.print("\n\nEnter a number to search: "); // print message

find= ox.nextInt(); // input number by user

for(x= 0;x< num.length;x++) //loop to count values

{

if(num[x] == find) //check value

{

find_in = true; //change value

in= x;

break; //using break keyword

}

}

if(find_in)  //find value

System.out.println(find + " is found at index " + in); // print location

else

System.out.println("Not found"); //message

// display count of each numbers

System.out.println("Count of each numbers:"); //message

for(y = 1; y< num.length; y++) // loop to store element in counts array  

{

tem = num[y]; //hold value

counts[tem]++; //increment value

}

for(x = 1; x< counts.length; x++) //loop to print value

{

System.out.println(x + ": " + counts[x]); // print value

}

// average of the numbers in the array

for(x = 0; x < num.length; x++) // loop to calculate sum and average

{

sum += num[x]; //calculate sum

}

avg = (sum / 100); // calculate avg

System.out.println("\nThe average of the numbers in the array: " + avg);

// highest number in the array

int high= num[0]; //find number

for(x= 0;x < num.length;x++)

{

if(num[x] > high)

high = num[x]; //hold value of highest Number

}

System.out.println("\nThe highest number is: " + high); //print value

int low = num[0]; // defining variable for lowest number

for(x= 0; x < num.length - 1; x++) // loop to calculate lowest number

{

if(num[x] < low) //condition for lowest number

low = num[x]; //hold lowest number

}

System.out.println("\nThe lowest number is: " + low); //print value

}

public static int generateRandomNumber() //defining function  

{

Random ra = new Random(); //creating Random function Object

return (ra.nextInt(100)+ 1); //input and return value

}

}

Output:

the output of the given code is display in image

Explanation:

In the above program, an array is declared that uses a random function to input the number, in the next step the sort function is used, that sorted all array elements, in the next step the scanner class is used, that input the number form the user ends and pass search in the sorted array.

  • After searching the average of array elements is calculated. In this array we calculate the highest and lowest number of the array to print all the values the print method is used.
  • At the last, the rand method is used that generates the random number for the array and passes into a num array that prints the values.

7 0
3 years ago
Operands may be any of the following: (select all that apply) Group of answer choices constant or constant expression register n
attashe74 [19]

Answer:

constant or constant expression

register name

variable name (memory)

Explanation:

Literally, operand means data which an operation can be performed on. The operation could be an arithmetic or logical operation.

From the list of options, several operations can be performed on:

  • constants e.g. \pi = 3.14
  • registers and
  • variables e.g. (a + b)

<em>However, no operation can be performed on keywords and/or reserved words.</em>

3 0
3 years ago
Choose the answer. Janice's IT department found that her computer had a program on it that was collecting her personal informati
harkovskaia [24]

Answer:

Spyware

Spam is just unwanted soliciation, spoofing is making links appear as something else, pharming is creating a fake website for victims to use.

7 0
2 years ago
What permissions are needed in order to use a work online that is in the public domain?
Maurinko [17]
<h2 /><h2>⇒Written  \: permission  \: from \\  the  \: creator</h2>

The term “public domain” refers to creative materials that are not protected by intellectual property laws such as copyright, trademark, or patent laws. ... Anyone can use a public domain work without obtaining permission, but no one can ever own it.

5 0
2 years ago
Where can I learn how you hack?​
morpeh [17]

Answer:

www.udemy.com

5 0
2 years ago
Read 2 more answers
Other questions:
  • The operation of the waste spark Ignition system is being discussed. technician a says that the spark that occurs on the exhaust
    14·1 answer
  • Explain the term remote backup with examples.​
    5·1 answer
  • From the standpoint of the governing bodies of .com, why is it important that owners of individual domains maintain authoritativ
    5·1 answer
  • The ________________ command tests connectivity by sending an echo request to a remote computer.
    14·1 answer
  • Go online and research the computer topic
    6·1 answer
  • William found out that someone used his report on American culture without his permission. What is William a victim of?
    8·2 answers
  • End user needs assessment is a formal procedure to analyze a user's computer needs; it involves a specific set of steps that are
    8·1 answer
  • Literally no one helps answer my questions so this website is pointless.... : /
    11·1 answer
  • The advancements in which of the following technologies has most changed the American job market in recent years?
    14·2 answers
  • Question 8 of 10
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!