+ 1
Why do i get this error, and how do i fix it?
import random as r import time symbols = ["0", "1", " ", " "] line = 1 counter = 0 for i in range (110): x = r.randint (0, 3) line. append(symbols[x]) counter +=1 for i in range (10000): if counter % 5 == 0: r_symbols = [r.randint (0, 117) for x in range (10)] for i in symbols: line[i] = symbols[r.randint (0, 3)] print(*line) counter += 1 time.sleep(0.01) OUTPUT Traceback (most recent call last): line. append(symbols[x]) AttributeError: 'int' object has no attribute 'append'
3 ответов
+ 1
#Final Code
import random as r
import time
symbols = ["0","1","",""]
line = [1]
counter = 0
u = 0
for i in range (110):
x = r.randint (0, 3)
line.append(symbols[x])
counter +=1
for i in range (10000):
if counter % 5 == 0:
r_symbols = [r.randint(0, 117) for x in range (10)]
for i in symbols:
line[x] = symbols[r.randint (0, 3)]
u += 1
print(*line)
counter += 1
time.sleep(0.01)
+ 1
✅Changing " line = 1 " to "line = [1]" may fix your problem !!
▶️You got that error because int data type don't have any method called append !!
0
I changed "line = 1" to "line = [1]" and now i get this error message
Traceback (most recent call last):
line[i] = symbols[r.randint (0, 3)]
TypeError: list indices must be integers or slices, not str