Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Count Consecutive Summers by ail531
def count_consecutive_summers(num):
count = 1 ## As always at least once.
for i in range(1, num): ## Stop before the last one.
sum_for_checking = i
for j in range(i+1, num):
if sum_for_checking == num:
count += 1
break
sum_for_checking += j
if sum_for_checking > num:
break
return count
if __name__ == '__main__':
# These "asserts" are used for self-checking and not for an auto-testing
print("Example:", count_consecutive_summers(42))
assert count_consecutive_summers(42) == 4
assert count_consecutive_summers(99) == 6
assert count_consecutive_summers(1) == 1
print("Coding complete? Click 'Check' to earn cool rewards!")
Jan. 30, 2020