About the sum of user' natural numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

About the sum of user' natural numbers

So,It's kinda hard to explain,but I need some directions I want to make a Python code to get a user input of a natural number,put it into a while loop(or a better alternative) to request a new natural number to sum it the previous,until it's a zero or negative number. The thing is,I'm a lazy guy(improving to be better) so I just need some hints to figure out something. The problem doesn't need to have functions. Thanks for the attention

20th Nov 2017, 6:18 PM
Rafael Figueiredo
Rafael Figueiredo - avatar
3 Answers
+ 9
Your code is ok but the if statement is not necessary as the loop will break anyway when nat becomes less than zero(ur while statement takes care of that) also u can't request for user input dynamically on sololearn as sololearn compiler takes all input at once, runs the code and returns the result
20th Nov 2017, 8:27 PM
David Akhihiero
David Akhihiero - avatar
+ 7
Sorry but your question is confusing, what are u trying to do
20th Nov 2017, 8:14 PM
David Akhihiero
David Akhihiero - avatar
+ 2
In resume,I need hints on how to make a program tha takes a user input as a natural number,makes a loop that keeps adding natural numbers to a sum and end the loop with 0 or negative. also print the total sum. I'm yrying like this nat = int(input("Type a number")) while nat >= 1: print(nat) nat = nat + int(input("Type a number")) if nat <= 0: break print (nat)
20th Nov 2017, 8:21 PM
Rafael Figueiredo
Rafael Figueiredo - avatar