Mailing List Archive

Did i debug this code correctly?
I am trying to solve this job task given to my girlfriend and here's the task and what i did

~ The two Python functions liDDA and liB are supposed to solve the same task. Firstly, explain
the task clearly and then fix any semantic errors in the two algorithms (so that they actually do
solve the task correctly).

#Suppose you have found the following (incomplete) Python code on a scrap
#The two Python functions are not quite finished and contain some errors.
-Firstly, give a detailed critique of the incomplete Python code given above. Secondly, fix any syntax errors so that the Python code runs, ensure the code follows good Python coding style and improve all the variable and function names.

def liDDA(a,b,c,d)
P = []
e = c-a
f = d-b
s = max(e,f)
x,y = a,b
for i in range(s):
P.append((round(x), round(y)))
x += e/s
y += f/s
print(P)

liDDA(0,1,6,4)#when running this function i got this
= [.(0, 1), (1, 2), (2, 2), (3, 2), (4, 3), (5, 4)]

Second function

#function 2 to do same task
def liB(a,b,c,d)
P = []
e = c-a
f = d-b
g = 2*f - e
y = b
for x in range(a,c+1)
P.append((x,y))
if (g>0)
y += 1
g = g - 2*e
g = g + 2*f
print(P)
liB(0,1,6,4)
--
https://mail.python.org/mailman/listinfo/python-list
Re: Did i debug this code correctly? [ In reply to ]
Preamble: this list strips attachments. If you attached some screenshots
orfile attachments, we do no receive them. We generally don't like
screenshots unless they're vital to demonstrating some visual thing. We
_much_ prefer text pasted inline in the message.

So the below is written about a message with no attachments.

On 21Sep2022 05:49, tripd...@gmail.com <tripdarlinq@gmail.com> wrote:
>I am trying to solve this job task given to my girlfriend and here's the task and what i did
>
>~ The two Python functions liDDA and liB are supposed to solve the same task. Firstly, explain
>the task clearly and then fix any semantic errors in the two algorithms (so that they actually do
>solve the task correctly).

Well, as near as I can tell you've not explained the task. It isn't
apparent to me what the purpose of either function is. I can see what
they _do_, but I have no idea why.

Without knowing the intended task, it is impossible to "fix" either of
them because we don't know what the "correct" behaviour should be.

>#Suppose you have found the following (incomplete) Python code on a scrap
>#The two Python functions are not quite finished and contain some errors.
>-Firstly, give a detailed critique of the incomplete Python code given above. Secondly, fix any syntax errors so that the Python code runs, ensure the code follows good Python coding style and improve all the variable and function names.

I don't see any critique either.

What I do see is no comments or docstrings. That would be the first
thing I would want to change, probably followed by more expressive
variable names.

BTW, the second function contains a syntax error, and would not run.

Cheers,
Cameron Simpson <cs@cskk.id.au>
--
https://mail.python.org/mailman/listinfo/python-list