Computer Science, asked by sheethalsriramp7ty04, 2 months ago

sum=0

i=1

while (i<=10):

sum=sum+i

i=i+1

print(“sum=”,sum) rewrite in for loop

Answers

Answered by rush5011
2

Answer:

hello friend your answer is in the attachment

have a great day ahead

Attachments:
Answered by Jasleen0599
0

Rewrite in for loop

sum = 0

i = 0

for i in range(10):

 sum = sum + i

 print (sum)

Output

0

1

3

6

10

15

21

28

36

45

  • The sum() method in Python determines the sum of all numerical values included in an iterable. Both floating-point numbers and integers can be used with sum(). A number can be added to the total using the optional parameter of the sum() function. Python's easy-to-use while loop and if statement can be used to calculate the sum of n numbers. taken a user-inputted number and put it in the variable num.
  • Till num reaches 0, iterate using a while loop. When num is added to sum during each iteration, its value is reduced by 1 in each iteration.

#SPJ2

Similar questions