0

When I am trying to append data, it gives list index out of range error.

n = int(input('Enter Range'))
arr=[]
for i in range(0,n):
    print(i)
    arr[i].append(input('Enter Number'))
arr.sort()
print(arr)
1
  • 2
    arr[i].append should be arr.append Commented Oct 13, 2018 at 14:08

1 Answer 1

2

arr.append() function will append element to the end of the list

n = int(input('Enter Range'))
arr=[]
for i in range(0,n):
    print(i)
    arr.append(input('Enter Number')) # Modify this line
arr.sort()
print(arr)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks buddy, I am a newbie and I made a silly mistake.
for sure buddy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.