# we import all necessary methods and objects
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer
from qiskit.tools.visualization import matplotlib_circuit_drawer as drawer
from random import randrange

# we will use 10 quantum bits and 10 classical bits
qreg3 =  QuantumRegister(10)
creg3 = ClassicalRegister(10)

mycircuit3 = QuantumCircuit(qreg3,creg3)

# we will store the index of each qubit to which x-gate is applied
picked_qubits=[] 

for i in range(10):
    if randrange(2) == 0: # Assume that 0 is Head and 1 is Tail
        mycircuit3.x(qreg3[i]) # apply x-gate
        print("x-gate is applied to the qubit with index",i)
        picked_qubits.append(i) # i is picked

# measurement 
mycircuit3.measure(qreg3,creg3)    

print("Everything looks fine, let's continue ...")

# draw the circuit
drawer(mycircuit3)
# reexecute me if you DO NOT see the circuit diagram

def print_outcomes(counts): # takes a dictionary variable
    for outcome in counts: # for each key-value in dictionary
        reverse_outcome = ''
        for i in outcome: # each string can be considered as a list of characters
            reverse_outcome = i + reverse_outcome # each new symbol comes before the old symbol(s)
        print(reverse_outcome,"is observed",counts[outcome],"times")

# execute the circuit and read the results
job = execute(mycircuit3,Aer.get_backend('qasm_simulator'),shots=128)

counts = job.result().get_counts(mycircuit3)
print_outcomes(counts)