adding numbers in a list Nickd12 Wafer-Thin Wafer Posts: 83 Threads: 31 Joined: Aug 2020 Reputation: Jan-15-2021, 03:59 AM what im looking to do is add 25 to elements in a list but add 25 plus the last number example list = [0,0,0,0] i want the output to be list = [0,25,50,75] Reply bowlofred Da Bishop Posts: 1,194 Threads: 3 Joined: Mar 2020 Reputation: Jan-15-2021, 05:49 AM 25 plus the last number plus the spot on the first list? What would be the answer if the first list were [5, 10]? Reply Serafim Lumberjack Posts: 100 Threads: 0 Joined: Jan 2021 Reputation: Jan-15-2021, 12:46 PM If I follow the example ```>>> def add_num_to_list(lst, num): ... new_list = [lst[0]] ... for i in lst[1:]: ... new_list.append(i+num+new_list[-1]) ... return new_list ... >>> print(add_num_to_list([0,0,0,0], 25)) [0, 25, 50, 75] >>> print(add_num_to_list([5,10], 25)) [5, 40]```Where the last printout is an answer to the question asked by @bowlofred But if I follow the text description: ```>>> def add_num_to_list(lst, num): ... new_list = [] ... for i in lst: ... new_list.append(i+num+(new_list[-1] if new_list else 0)) ... return new_list ... >>> print(add_num_to_list([0,0,0,0], 25)) [25, 50, 75, 100] >>> print(add_num_to_list([5,10], 25)) [30, 65] >>> ``` Reply