+ 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'

2nd Dec 2018, 12:45 PM
FlaviusKID
FlaviusKID - avatar
3 Answers
+ 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)
3rd Dec 2018, 7:56 AM
Parth
Parth - avatar
+ 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 !!
2nd Dec 2018, 1:39 PM
Parth
Parth - avatar
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
3rd Dec 2018, 7:07 AM
FlaviusKID
FlaviusKID - avatar