# How can I print out the probability of a certain state in histogram?

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:

print(counts['0001'])

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:

sum(counts.values())

and from this print the probability:

print(counts['0001'] / sum(counts.values()))
• Thanks!! That helps:) – ZR- Sep 3 '20 at 19:28