Python Forum
can someone explain what I need to do here?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
can someone explain what I need to do here?
#1
1. (a) Trace (by hand) the execution of the following Python program by completing
the trace table below. For Each line of code (as labelled with line numbers), you
would enter the line number in the trace table, the state/value of the variable(s)
that is/are affected within that line, and any output displayed by that line.
Note: Tracing a program with test data is a good mechanism to see if your code
is working.
Python program:
from math import *
x = 13 #LINE 1
y = 2 #LINE 2
v = 120 #LINE 3
z = 9.0 #LINE 4
w = 1.15 #LINE 5
w = (x//y*100) #LINE 6
v = x/y*100 #LINE 7
w = w/1000 #LINE 8
v = int(w+999/1000) #LINE 9
w = 2.5+4*-1.5-(2.5+4)*-1.5 #LINE 10
x += 1 #LINE 11
w = x%y * pow(x*y/4,y) #LINE 12
v = int((6+int(w))/x ) #LINE 13
w = x*float(20/8) #LINE 14
a = y%x #LINE 15
print("Sum of w,x,y is: " + ’w+x+y’) #LINE 16
print("Price per litre is $%.2f" %((w+x+y+z)% 59)) #LINE 17
b = "Supercalifragilisticexpialidocious" #LINE 18
c = len(b) #LINE 19
d = b[0:5]+" "+b[27].upper()+b[3]+b[7]+b[8]+b[-5:] #LINE 20
2
Trace table:
Line number x y v z w Output
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Note: to submit your solution for this question you can create a new file in idle
and save it with a .txt extension (rather than a .py extension).






I don't get what am I supposed to do.
Reply
#2
(Sep-19-2020, 05:30 AM)pedicurecurator Wrote: For Each line of code (as labelled with line numbers), you
would enter the line number in the trace table, the state/value of the variable(s)
that is/are affected within that line, and any output displayed by that line.
What exactly is unclear?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
This is a manual action. You must fill in (in Word, Excel or whatever) a table. Like this:
Output:
Line number x y v z w Output ----------- -- -- -- -- -- ------ 1 13 2 13 2 3 13 2 120 ...
And so on.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020