Answer the attachment :P
Attachments:
Answers
Answered by
6
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.
Attachments:
AbhijithPrakash:
Cool!
Answered by
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:
Similar questions
English,
5 months ago
Computer Science,
11 months ago
English,
11 months ago
Science,
1 year ago
Physics,
1 year ago