This program calculates the sum of all natural numbers between the given starting value and ending value using a for loop. The user is prompted to enter the starting value and ending value. The for loop iterates through the range of values between the starting value and ending value (inclusive). Within the loop, a variable called "result" is initialized to zero, and the current value of x is added to it. The final sum is printed out as "Sum of natural number is [result]" after the loop is completed.
print("Sum of Natural Number using for loop ") start = int(input("Enter the starting value : ")) end = int(input("Enter the ending value : ")) result=0 for x in range(start,end+1): result=result+1 print("Sum of natural number is ",result)To download raw file Click Here
Sum of Natural Number using for loop Enter the starting value : 1 Enter the ending value : 10 Sum of natural number is 10
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions