Python Forum

Full Version: why is the append function gets empty on the loop?/python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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:
        demands.append('Up.')
      elif n_n < f_n:
        demands.append('Down.')
      f_n = n_n
    else:
        finished = True
print (demands)
your indentation is all messed up.
use 4 spaces per indent (PEP8).
if ... elif ... else: like:
if whatever():
    ...
elif anywho():
    ...
else:
    ...
You redefine demands each time through the loop (line 15), deleting any previously stored data. You should define it once before the loop.
Thank you ichabod801 ^_^. it worked! thank you thank you!!!!