I wrote such script

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.)

```
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.)

asked March 23rd 20 at 19:03

1 answer

answered on 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.

2.

3. You access elements of an empty array.

Use the append to extend array.

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