0
How to write a program to find the sum of first n natural numbers using while loop in python??
4 Answers
+ 1
# python program to find the sum of first n natural numbers using while loop :-
num = int(input("Enter the number\n"))
sum = 0
while num > 0 :
sum = sum + num
num-=1
print("The sum of first natural number is ", sum)
+ 5
Show us your code. We can't help if we don't know where the issue is.
If you want to add numbers, you need a variable (abc) and increase it.
(abc += N)
you can check in the lesson how the while loop works. you just need a variable outside that loop and increase it with the number in the loop.
0
🍇 Alex Tușinean 💜
Why its not working..
https://code.sololearn.com/cy10OtPojRg8/?ref=app
0
🍇 Alex Tușinean 💜 Thanks 😊