I am getting an attribute error for the following code :
coininfo = [ {} for k in range(0,numberOftrials)]
coininfo[i].append([x,outcome(x)])
The following is the exact error screen i am getting:
Traceback (most recent call last):
File "pr1.py", line 22, in <module>
runsimulation(numberOftrials,numberOfcoins)
File "pr1.py", line 19, in runsimulation
coininfo[i].append([x,outcome(x)])
AttributeError: 'dict' object has no attribute 'append'
Any help is appreciated!
When you run
coininfo = [ {} for k in range(0,numberOftrials)]
you end up with an array of dictionaries, not an array of arrays. Thus coininfo[i]
is a dictionary, and you can't append to it.
My guess is that you want to change your first line to
coininfo = [ [] for k in range(0,numberOftrials)]
so you will instead have an array of arrays. Alternative, if you mean for your output to be an array of dictionaries, you may mean to have
coininfo[i][x] = outcome(x)
instead of
coininfo[i].append([x,outcome(x)])