Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 why is the append function gets empty on the loop?/python
im trying to print all the result of the comparison of each input integers in one line. But it looks like that my list becomes empty as the loop goes. any idea how to do it? here is my code so far. Thanks

f_n = 0
n_n = 0

print('Enter the first number: ' , end = ' ')
fn = input()
f_n = int(fn)

finished = False
while not finished:
    print('Enter the next number, 0 to finish: ' , end = ' ')
    nu = input()
    n_n = int(nu)
    if n_n != 0:
      demands = []
      if n_n == f_n:
        demands.append ('Same.')
      elif n_n > f_n:
      elif n_n < f_n:
      f_n = n_n
        finished = True
print (demands)
Larz60+ wrote Jul-07-2018, 07:56 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

I added for you this time, please do so on future posts.

Thank You
your indentation is all messed up.
use 4 spaces per indent (PEP8).
if ... elif ... else: like:
if whatever():
elif anywho():
You redefine demands each time through the loop (line 15), deleting any previously stored data. You should define it once before the loop.
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Thank you ichabod801 ^_^. it worked! thank you thank you!!!!

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Use range to add char. to empty string johneven 4 964 Apr-15-2019, 11:21 PM
Last Post: scidam
  Help With While Loop and Append laprus 13 742 Feb-07-2019, 07:04 AM
Last Post: perfringo
  Help with while loop creating an infinite loop. FWendeburg 3 365 Jan-30-2019, 08:28 PM
Last Post: FWendeburg
  why is this not filling my empty list? Siylo 4 372 Jan-21-2019, 05:27 PM
Last Post: Siylo
  Writing python function difficulty kirito85 5 565 Oct-28-2018, 07:34 AM
Last Post: buran
  beginning python help request (for loop) casey 3 528 Oct-26-2018, 07:26 PM
Last Post: casey
  Python Tutorial range function question HawkeyeKnight 2 487 Sep-27-2018, 09:45 AM
Last Post: ThiefOfTime
  Issues with Inserting Values into an Empty List with a While Loop TommyMer 2 604 Sep-12-2018, 12:43 AM
Last Post: TommyMer
  Help with 'while' loop! Python 3 rafaelssouzza 2 525 Sep-03-2018, 06:19 PM
Last Post: woooee
  Python, While loop & lists jaki 1 582 Jun-28-2018, 11:14 AM
Last Post: ichabod801

Forum Jump:

Users browsing this thread: 1 Guest(s)