<reponame>A1fus/programmingWithPython<filename>week2-class/consecutiveSum.py
# -*- coding: utf-8 -*-
"""
A program that loads a natural number n and prints in how many ways can n be written as a sum of consecutive natural numbers (including the one element sum of n alone).
"""
n = -1
counter = 0

while n < 0: #Guarantees the input of a natural number
    n = int(input("Enter a natural number: "))

for i in range(n+1): #Largest number in the sum
    for y in range(i): #When y is 0, the following if sums all the numbers from 1 to i, then 2 to i when y=1 and so on
        if (i*0.5*(i+1)) - (y*0.5*(y+1)) == n: #If the sum of consecutive numbers is exactly n then the counter is incremented
            counter += 1

print("There are ", counter, "ways to sum to", n, "with consecutive integers.")

# -*- coding: utf-8 -*-
"""
A program that loads a natural number n and prints in how many ways can n be written as a sum of consecutive natural numbers (including the one element sum of n alone).
"""
n = -1
counter = 0

while n < 0: #Guarantees the input of a natural number
    n = int(input("Enter a natural number: "))

for i in range(n+1): #Largest number in the sum
    for y in range(i): #When y is 0, the following if sums all the numbers from 1 to i, then 2 to i when y=1 and so on
        if (i*0.5*(i+1)) - (y*0.5*(y+1)) == n: #If the sum of consecutive numbers is exactly n then the counter is incremented
            counter += 1

print("There are ", counter, "ways to sum to", n, "with consecutive integers.")
# -*- coding: utf-8 -*- A program that loads a natural number n and prints in how many ways can n be written as a sum of consecutive natural numbers (including the one element sum of n alone). #Guarantees the input of a natural number #Largest number in the sum #When y is 0, the following if sums all the numbers from 1 to i, then 2 to i when y=1 and so on #If the sum of consecutive numbers is exactly n then the counter is incremented