Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

code example of sum of the first n odd numbers using for loop

def OddSummation(n):
    total = 0
    for i in range(1,n,2):
        total+=i
    return total
    
    
def main():
    number = int(input("Enter the number: "))
    print("The summation of all the odd numbers between 1 and ",number, " is ",         OddSummation(number))
    
main()
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #code #sum #odd #numbers #loop
ADD COMMENT
Topic
Name
7+9 =