The program must convert two numbers into a list with a number that is also given in the parameter. I can not change the parameters, but I can also create other functions. Apart from this, I should use recursion yet I have learned how to replace with recursion, but I'm confused about counting every time I try, the first two events of 'only' 'Instead, I always replace' x 'with' y '. EDIT: And I can not use global variable
def change two (x, y, lst): if lst == []: return [] else: if lst [0] == X: returns [y] + change just t (X, Y, LST [1:]) Other: Return [List [0]] + Change Fast Tevo (X, Y, LST [1:])
Should appear:
replaceFirstTwo (1,2, [5,1,2,3,1,1]) [5, 2, 2, 3, 2 if x is going to be positive only So, you can use, negative version indicates that this is the second time that you are running the function. Do something before changing the X to do something. I modified your function, it does, though it will not work with negative values of x as abs (x)
will make it positive.
Change DefaultsFSTATOVO (X, Y, LST): If lst == []: Return [] AND: If X is not anybody: if lst [0] == Abs (x) : If x & gt; -1: x = -x Other: x = No return [y] + Replacement prestova (X, Y, LCT [1:]) Other: Return [List [0]] + Replace Faststavo (X, Y, LCS [1:]) Other: Return [List [0]] + FirstSTwo replacement (x, y, lst [1:])
Comments
Post a Comment