Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can i please have some help with these two trace table python questions? QUESTIO

ID: 3590388 • Letter: C

Question

Can i please have some help with these two trace table python questions?

QUESTION 1

One effective method often used by programmers to comprehend the effect of code is "tracing". Tracing is hand-executing the code in the same sequence and manner that the computer would execute the program. Often, the changes made to variables in the code are recorded in a "trace table". Each row in the trace table records the values of the variables after a corresponding statement in the left hand column of the trace table has been hand-executed.

For example, for the code

holden = 2
ford = 13
mitsubishi = 5

a completed trace table would be:

holden

ford

mitsubishi

holden = 2

2

-

-

ford = 13

2

13

-

mitsubishi = 5

2

13

5

Your task is to trace execution of the following Python code and keep track of variables index, where and answer:

index

where

answer

nums = [3, 1, 2, 10]

-

-

-

where = 0

-

0

-

for index in range(1, len(nums)):

#<first iteration of the loop> (TRACE TABLE STARTS HERE, FILL IN THE BLANK BOXES BELOW)

  if nums[index] < nums[where]:

     where = index

#<second iteration of the loop>

  if nums[index] < nums[where]:

     where = index

#<third iteration of the loop>

  if nums[index] < nums[where]:

     where = index

# end loop

answer = nums[where]

QUESTION 2

One effective method often used by programmers to comprehend the effect of code is "tracing". Tracing is hand-executing the code in the same sequence and manner that the computer would execute the program. Often, the changes made to variables in the code are recorded in a "trace table". Each row in the trace table records the values of the variables after a corresponding statement in the left hand column of the trace table has been hand-executed.

For example, for the code

holden = 2
ford = 13
mitsubishi = 5

a completed trace table would be:

holden

ford

mitsubishi

holden = 2

2

-

-

ford = 13

2

13

-

mitsubishi = 5

2

13

5

Your task is to trace execution of the following Python code and keep track of variables last and which:

last

which

numbers1 = [5, 50, 500]

-

-

numbers2 = [10, 20, 500]

-

-

last = -1

-1

-

which = 0

-1

0

while which < len(numbers1):

#<first iteration of the loop> (TRACE TABLE STARTS HERE, FILL IN THE BLANK BOXES BELOW)

    if numbers1[which] >= numbers2[which]:

        last = which

    which = which + 1

#<second iteration of the loop>

    if numbers1[which] >= numbers2[which]:

        last = which

    which = which + 1

#<third iteration of the loop>

    if numbers1[which] >= numbers2[which]:

        last = which

    which = which + 1

holden

ford

mitsubishi

holden = 2

2

-

-

ford = 13

2

13

-

mitsubishi = 5

2

13

5

Explanation / Answer

Trace Table is a table to trace the variable values and flow of the program with each step. Following are the answers of the questions given.

Answer 1 :

index

where

answer

nums = [3, 1, 2, 10]

-

-

-

where = 0

-

0

-

for index in range(1, len(nums)):

#<first iteration of the loop> (TRACE TABLE STARTS HERE, FILL IN THE BLANK BOXES BELOW)

  if nums[index] < nums[where]:

     where = index

#<second iteration of the loop>

  if nums[index] < nums[where]:

     where = index

#<third iteration of the loop>

  if nums[index] < nums[where]:

     where = index

# end loop

answer = nums[where]

Answer 2:

last

which

numbers1 = [5, 50, 500]

-

-

numbers2 = [10, 20, 500]

-

-

last = -1

-1

-

which = 0

-1

0

while which < len(numbers1):

#<first iteration of the loop> (TRACE TABLE STARTS HERE, FILL IN THE BLANK BOXES BELOW)

    if numbers1[which] >= numbers2[which]:

        last = which

    which = which + 1

#<second iteration of the loop>

    if numbers1[which] >= numbers2[which]:

        last = which

    which = which + 1

#<third iteration of the loop>

    if numbers1[which] >= numbers2[which]:

        last = which

    which = which + 1

NOTE :

index

where

answer

nums = [3, 1, 2, 10]

-

-

-

where = 0

-

0

-

for index in range(1, len(nums)):

#<first iteration of the loop> (TRACE TABLE STARTS HERE, FILL IN THE BLANK BOXES BELOW)

  if nums[index] < nums[where]:

1 0 -

     where = index

1 1 -

#<second iteration of the loop>

  if nums[index] < nums[where]:

2 1 -

     where = index

2 1 -

#<third iteration of the loop>

  if nums[index] < nums[where]:

3 1 -

     where = index

3 1 -

# end loop

answer = nums[where]

- 1 1