The following procedure is intended to return true if the list of numbers myList contains only positive numbers and is intended to return false otherwise. The procedure does not work as intended. PROCEDURE allPositive(myList) { index ←← 1 len ←← LENGTH(myList) REPEAT len TIMES { IF(myList[index] > 0) { RETURN(true) } index ←← index + 1 } RETURN(false) } For which of the following contents of myList does the procedure NOT return the intended result?

Respuesta :

Answer:

[-1, 0, 1]

Explanation:

Given

The above procedure

Required

Which list does not work as intended

The question has missing options (the options are available online).

From the question, we understand the procedure is to return true for lists that contain only positive numbers.

However, the list does not work for [-1, 0, 1]

The reason is that; the procedure starts checking from index 1.

i.e. index ←← 1

In [-1, 0, 1], the element at index 0 is negative (-1).

Since the procedure starts checking from index 1, the procedure will not check the element at index 0 (i.e. -1).

Hence, it will return true, instead of false

In this exercise we have to use the knowledge of computational language in python, so we have that code is:

It can be found in the attached image.

So, to make it easier, the code in python can be found below:

NumList = []

Number = int(input("Please enter the Total Number of List Elements: "))

for i in range(1, Number + 1):

   value = int(input("Please enter the Value of %d Element : " %i))

   NumList.append(value)

print("\nPositive Numbers in this List are : ")

for j in range(Number):

   if(NumList[j] >= 0):

       print(NumList[j], end = '   ')

See more about python at brainly.com/question/2266606

Ver imagen lhmarianateixeira
ACCESS MORE
EDU ACCESS