0

I am trying to append numbers into a list already created when prompted for the number.

Here is the code I have so far.

x = [1, 2, 3, 4, 5]
y = raw_input("Enter a number: ")
for numbers in y:
    if y > 5:
        x.append(y)
        print x
    else:
        print "List remains the same"

But, even if I type in 3, it still appends it to the list.

thefourtheye
  • 233,700
  • 52
  • 457
  • 497

1 Answers1

0

This is one way to do it in Python 2:

x = [1,2,3,4,5]
y = int(raw_input("Enter a number: "))
if (y) > 5:
    x.append(y)
    print x
else: print "List remains the same"
Joe T. Boka
  • 6,554
  • 6
  • 29
  • 48
  • Please do not advocate the usage of `input` - it's dangerous. – orlp May 31 '15 at 02:29
  • @orlp the OP must be using Python 2 because he originally used `raw_input` this is why I put `input` – Joe T. Boka May 31 '15 at 02:31
  • I know, that was not my point. You should __never__ use `input`. It uses `eval`, and is a lazy and dangerous solution. – orlp May 31 '15 at 02:31