I am trying to assign strings to a list "a" based on the value generated randomly. but when I run the code, I get this error:
a[i]="INT" IndexError: list assignment index out of range
import random
a= list()
for i in range(35):
b=random.randint(0,1)
if b==0:
a[i]="Internet"
else:
a[i]="Library"
print(a[5])
fout=open("/Users/BATTLEDRUM/Desktop/review.txt","w")
for i in range(len(a)):
fout.write(a[i]+"\n")
print(a.count("Library"))
What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire