77.8k views
0 votes
list [11, 35, 6, 0] display (mystery (list)) procedure mystery (list) { sum 0 for each item in list { sum sum item } return sum / length (list) }

User DownChapel
by
8.2k points

1 Answer

7 votes

The given procedure mystery(list) takes in a list as an argument and performs the following actions:

Initializes a variable sum to 0

Loops through each item in the list

Adds the current item to the sum variable

After the loop, it returns the value of sum divided by the length of the list.

When the list [11, 35, 6, 0] is passed to the procedure, the following steps occur:

The variable sum is initialized to 0

The first item in the list is 11, so 11 is added to sum

The second item in the list is 35, so 35 is added to sum

The third item in the list is 6, so 6 is added to sum

The fourth item in the list is 0, so 0 is added to sum

The procedure returns the value of sum (52) divided by the length of the list (4), which is 13

So the output of the procedure when passed the list [11, 35, 6, 0] is 13.

User Ttsiodras
by
8.3k points