python - traced my code and it seems to be in a continous loop -


So I'm trying to write a program that takes positive, negative numbers and then once entered After it displays them at the end,

  pos1 = 0 neg1 = 0 all1 = 0 flt1 = float (raw_input ("Enter non-zero floating point number (decimal):") while (Flt1! = 0.0): if (Flt1 & lt; 0.0): neg1 = neg1 + flt1 all1 = all1 + flt1 elif (flt1> 0.0): pos1 = pos1 + flt1 all1 + all1 + flt1 print " Sum of all numbers ", all1," the all positive The sum of the numbers is "pause 1, print" and is the sum of all negative numbers ", neg1,  

My problem is that when I actually detect it (if I say 5.0 and trace it) I see that it gets stuck on the "elif" part of the code and is not really coming back to ask for the second number. I am trying to figure out what to do to get it back and ask for any other non-zero number. My goal is that the user enters the number in which he enters 0, then he takes all the negatives and combines them together and displays them, then also does for the positive and then displaying the entire amount (Negativity and position) So far 0 works but nothing else

Edit: fixed indentation on the elife loop

just inside the loop flt1 = ... Put the line

Also, you generally avoid the comparison of float parity, though zero is OK.

And you should use white space ( n = 72 + 61 * x , not n = 72 + 61 * x ).

Pseudocode:

  is correct, while: num = input if num & gt; 0.0: do_stuff () Alif Number & lt; 0.0: do_neg_stuff () Other: Break  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -