(Mar-25-2018, 11:31 AM)pythoneer Wrote: could you please explain this a bit for my understanding
This is a relatively short code. I don't know what you don't understand. You can perhaps add a few print() statements to trace some values while the program runs.
it is working , i am trying to understand python through this forum, what will be the code if i want to get the output as follows, the change from the last time is the last column is accumulation of numbers
[inline] 500 125.0 31.25
500 125.0 68.75
500 125.0 125.0
500 150.0 170
500 150.0 237.5
500 150.0 275
500 225.0 376.25
500 225.0 432.5
500 225.0 500[/inline]
def gen_result(number, divisors):
total = sum(divisors)
acc = 0
for i, d in enumerate(divisors):
num2 = number * d / total
for d2 in divisors[i:] + divisors[:i]:
acc += num2 * d2 / total
yield [number, num2, acc]
for item in gen_result(500, [5, 6, 9]):
print('{} {} {}'.format(*item))
wow, it works well, i am slowly understanding python now. What should i do if i want to do the same operation in range of numbers range(500,504,2) with each range ending with that range number and the next range should start adding from that number