I am trying to make a function that will make a list of all the cubes less than n. Then all those numbers together and print that out however the .count() doesn't work as I was hoping. Is there a way to count up every number of the list or do I have to go through the list one by one to add them up?
def sum_cubes_less(n): '''Return the sum of the cubes of the positive integers less than n.''' x = 1 cubes = [x**3 for x in range(1,n)] return cubes.count() print(sum_cubes_less(2**8))
sum()is probably what you're looking forsum([1,2,3])gives you 6. Check out official doc