# How can I make qiskit output raw data?

I am new to quantum computing, and I want to make a program to output 0 or 1 randomly by Hadamard gate, and use that information to make a GUI interface. For example, a coin flip program that output "Tail" when it is 1, and "Head" when it is 0. However, when I try to get raw data by job.result(job), I get the information of the result instead. By the way, here is the code:

from qiskit import *
simulator = Aer.get_backend('qasm_simulator')
qr = QuantumRegister(1)
cr = ClassicalRegister(1)
circuit = QuantumCircuit(qr, cr)
circuit.h(qr[0])
circuit.measure(qr, cr)
job = execute(circuit, backend = simulator, shots=1024)
a = job.result(job) #the problematic code
print(a)


I use Qiskit with Python, and do not use Jupyter notebooks.

## 1 Answer

You need to do .get_counts() to get a dictionary of the counts returned by the circuit. You would do this as follows

job = execute(circuit, backend = simulator, shots=100)
result = job.result()
counts_dict = result.get_counts()


Using your circuit and this code, counts_dict will look something like {'0':497, '1':503}. From there you might want to extract the key which has a higher value to be the result of your coin flip.

• thanks you! you are very helpful! May 7 '20 at 12:54