Computer Science, asked by Anonymous, 11 months ago

Answer the attachment :P​

Attachments:

Answers

Answered by Anonymous
6

\huge\mathbb{ANSWER}

sum=0

for n in range(1,8):

sum=sum+n

print("sum of natural number <=",n,"is",sum)

Note: screenshot of program is in attachment.

\huge\bold\red{THANK YOU }

Attachments:

AbhijithPrakash: Cool!
Answered by AbhijithPrakash
9

sum=0 # I too a black variable sum, so that we can put the sum of the natural numbers in it.

for i in range(1,8): # for loop from 1,8. This will give me the value of natural numbers one by one.

      sum+=i # When the sum is added to the natural number it'll change it's value.

      print("The sum of nutural numbers till {} is {}.".format(i,sum)) # This will print the sum one by one.

print("\nThe sum of all the natural numbers from 1 to 7 is {}.".format(sum)) # This will print the last value of sum.

Attachments:

Anonymous: Awesome
AbhijithPrakash: ^^"
Similar questions