Sum of the first ten positive integers

Q: Write a program that prints the sum of the first ten positive integers.





By Using for loop:
for i in range(0,10):
    print(i+1)


By Using while loop:


n = 1
while(n<=10):
    print(n)
    n+=1


By Using Recursive:


def Sum(CScientists):
    if CScientists == 10:
        return 10
    print(CScientists+1)
    return Sum(CScientists+1)

Start = 0
Sum(Start)

No comments:

Post a Comment