How to fix errors in the bubble sorter array?

I wrote such script

a = []
print("Enter the number of digits")
n = input()
i=0
while i < n:
 print("Enter array element ")
a[i]=int(input())
i+=1

k = 0
for i in range(n-1):
 for j in range(n-i-1):
 if a[j] > a[j+1]:
 a[j],a[j + 1] = a[j + 1], a[j]
 k += 1

print(k)
input()


generates errors. Please help fix script error. (It is necessary that you could choose the number of digits, then they fit, and then will give how many were replacements.)
March 23rd 20 at 19:03
1 answer
March 23rd 20 at 19:05
1. You mixed tabs and spaces. No matter how I found out about it XD For Python is important. Use a normal text editor such as VSCode.
5cf67edfef0ec629296918.gif
2.
n = int(input())
3. You access elements of an empty array.
a[i]=int(input())
Use the append to extend array.
for _ in range(n):
 print("Enter array element ")
 a.append(int(input()))

Find more questions by tags Python