+ 2

Can someone explain this....what is my mistake...that the sum is not come in a single line. It comes various tym.

x=int(input("enter sum of number:")) sum=0 for i in range(1,x+1,1): sum+=i print("Sum of number from 1 to",x,"are:",sum)

14th Apr 2021, 6:00 PM
Disha Jain
2 Réponses
+ 4
You need to print the output outside loop x=int(input("enter sum of number:")) sum=0 for i in range(1,x+1,1): sum+=i print("Sum of number from 1 to",x,"are:",sum)
14th Apr 2021, 6:04 PM
Simba
Simba - avatar
+ 3
Okkkkk..... thanku Simba
14th Apr 2021, 6:06 PM
Disha Jain