user7515414
user7515414

Reputation:

list index out of range - in python

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)

Upvotes: 0

Views: 69

Answers (1)

shirish
shirish

Reputation: 678

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)

Upvotes: 2

Related Questions