Loren Truesdale
List Operations
Jan 06, 8:31:34 AM
Determine what is printed by the following code.
1
2.
3
4
values - [9, 11, 0, 12, 9, 4]
fred - 0
FOR EACH value IN values
{
if( value = 9)
{
fred - fred + value
5
on
6
7
8
9
3
DISPLAY( fred)
10


Loren Truesdale List Operations Jan 06 83134 AM Determine What Is Printed By The Following Code 1 2 3 4 Values 9 11 0 12 9 4 Fred 0 FOR EACH Value IN Values If class=

Answer :

The output printed by the code is 18

The Code Analysis

The flow of the program is as follows:

  • The first line initializes a list of numbers named values
  • The second line initializes fred to 0
  • The third line is an iteration that is repeated for all numbers in the list
  • The next statement is a conditional statement that ensures that all 9's in the list are added, and saved in fred

The Code Computation

Recall that, the initial value of fred is 0, and there are 2 9's in the list.

So, the computation is:

[tex]fred=0 + 9 + 9[/tex]

[tex]fred=18[/tex]

This means that, the last instruction on line 10 will display 18, as the output

Hence, the output printed by the code is 18

Read more about algorithms at:

https://brainly.com/question/11623795