Професионална програма
Loading...
Tryhard avatar Tryhard 0 Точки

Number Beggars - Fundamentals PY

Здравейте, от два часа съм "зациклил" трябват ми насоки как да реша тази задача. 

1.Number Beggars

Your task here is pretty simple: given a list of numbers and a number of beggars, you are supposed to return a list with the sum of what each beggar brings home, assuming they all take regular turns, from the first to the last.

For example: [1,2,3,4,5] for 2 beggars will return a result of 9 and 6, as the first one takes [1,3,5], the second collects [2,4].

The same list with 3 beggars would produce a better outcome for the second beggar: 5, 7 and 3, as they will respectively take [1, 4], [2, 5] and [3].

Also note that not all beggars have to take the same amount of "offers", meaning that the length of the list is not necessarily a multiple of n; length can be even shorter, in which case the last beggars will of course take nothing (0).

Input

You will receive 2 lines of input: a single string containing the numbers separated by a comma and a space ", ". On the second line you will receive the number of beggars.

Output

Print a list of all the sums that each beggar got.

INPUT                  OUTPUT |         INPUT                      OUTPUT

1, 2, 3, 4, 5             [9, 6]      |         3, 4, 5, 1, 29, 4          [3, 4, 5, 1, 29, 4]

2                                           |        6

Тагове:
0
Fundamentals Module
vigyriousx avatar vigyriousx 9 Точки
coins = [int(num) for num in input().split(", ")]
beggars = int(input())
count = 0
beggars_list = [0] * beggars
for coin in coins:
    beggars_list[count] += coin
    count += 1
    if count >= beggars:
        count = 0
print(beggars_list)

Ето и моето решение на задачката. 100/100

0
Ina_K avatar Ina_K 0 Точки

Много леко и добро решение. Браво!

0