Did i debug this code correctly?

tripd...@gmail.com tripdarlinq at gmail.com
Wed Sep 21 08:49:59 EDT 2022


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)


More information about the Python-list mailing list