27 lines
837 B
Python
27 lines
837 B
Python
def count_consecutive_summers(num):
|
|
index = num
|
|
number_of_consecutive_summers = 1
|
|
while index > 0:
|
|
index -= 1
|
|
sums = index
|
|
count = 1
|
|
while sums <= num and index - count >= 0:
|
|
if sums == num:
|
|
number_of_consecutive_summers += 1
|
|
break
|
|
sums += index - count
|
|
count += 1
|
|
return number_of_consecutive_summers
|
|
|
|
|
|
if __name__ == '__main__':
|
|
print("Example:")
|
|
print(count_consecutive_summers(42))
|
|
|
|
# These "asserts" are used for self-checking and not for an auto-testing
|
|
assert count_consecutive_summers(42) == 4
|
|
assert count_consecutive_summers(99) == 6
|
|
assert count_consecutive_summers(1) == 1
|
|
assert count_consecutive_summers(15) == 4
|
|
print("Coding complete? Click 'Check' to earn cool rewards!")
|