Hey guys!Please,tell me,how could I fix the function ,so not to have None in output?
Create a function called
append_size that has one parameter named
The function should append the size of
lst (inclusive) to the end of
lst . The function should then return this new list.
For example, if
[23, 42, 108] , the function should return
[23, 42, 108, 3] because the size of
lst was originally
for i in lst1:
print(append_size([23, 42, 108]))
try looking at it with this tool:
you are using a loop over
lst1, which is empty, so no loop, and then the return statement is inside the loop
The function is supposed to append the size of lst to the end of itself. I would do that first and then just return lst. There is no reason to have a for loop.
You have copied over an assignment, but you haven’t talked about your solution. What do you need help with? What have you tried? What is behaving differently than you expect it to?
append the value with the type of variable.
I am hiding your solution, it is pretty rude and unhelpful to give the solution to someone asking for help
sorry i thought he wanted the solution.
Let’s take a look to your code. Your function receives as parameter a list which will be append to lst1, which is an empty list. Then, you start a loop over lst1, which is an empty list, for that reason the loop will never be performed. After that, you have: lst1.append(len(lst)), what you are telling here is that the len of the list “lst” will be append to lst1, this is, if you have 10 numbers in “lst”, then the number 10 will be added to lst1, not the numbers in lst but the amount of items in it, so you just need to remove len(). After that, you have a return, when you return something you “kill” the other processes, this is, the loop will stop on the 1st iteration, so you must change the return with a print or display, and finally, you can remove the print on the final line of code or as an output you’ll have lst1 + None.
I hope this helps.