This is a simulation I did in my program. I'm hoping to print out the probability of the state $|0001\rangle$ (which is $0.052$), and store this number in a letter (a). How can I do this? Thanks!!
.get_counts() returns a dictionary with the keys being the measured state and their corresponding values being the number of times that result was measured. To get the number of times that state was measured you can do:
To get probability, you need to divide this by the total number of shots. If you're not sure of the number of shots, you can sum the total number of shots in the dictionary using:
and from this print the probability:
print(counts['0001'] / sum(counts.values()))