Computer Science, asked by ayushpanwer123, 10 months ago

program to print sum of natural number between 1 to 7 in python​

Answers

Answered by varun000
6

n=int(input("Enter a number: "))

sum1 = 0

while(n > 0):

sum1=sum1+n

n=n-1

print("The sum of first n natural numbers is",sum1)

>>Runtime Test

Enter a number: 7

The sum of first n natural numbers is 28

Answered by AskewTronics
0

Below are the python program and output for the above question :

Output :

The above program will print "The sum of the natural number from 1 to 7 is:  28".

Explanation:

Total=0#variable which is used to hold the sum.

for count in range(1,8):#For loop which runs from 1 to 7.

   Total=Total+count#sum the value.

print("The sum of the natural number from 1 to 7 is: ",Total)#print the total sum of natural number.

Code Explanation :

  • The above program is in python language which has one for loop which runs from 1 to 7 and gives the value for the sum.
  • Then the total variable will add the value.
  • Then the Total value will be printed with the help of print function.

Learn More :

  • Python : https://brainly.in/question/14689905
Similar questions