-12

AttributeError: 'str' object has no attribute 'pop'

a = input('enter a list : ')
p = 2
i = 0
l = len(a)
while l>0:
    i = (p+i)%l
    print(a.pop(i))
    l -= 1

1 Answers1

3

a is assigned a string returned by input(), so you need to turn it into a list first before you can use list methods such as pop() on it.

For example, by using a.split() you can treat a as a space-delimited string:

a = input('enter a list : ')
n = a.split()
p = 2
i = 0
l = len(n)
while l>0:
    i = (p+i)%l
    print(n.pop(i))
    l -= 1

Sample input and output:

enter a list : 3 5 2 1
2
5
1
3
blhsing
  • 91,368
  • 6
  • 71
  • 106