from qiskit import *
from qiskit.tools.visualization import plot_histogram
%matplotlib inline

qr1 = QuantumRegister(2)
cr1 = ClassicalRegister(2)

circuit1 = QuantumCircuit(qr1,cr1)
circuit1.draw(output='mpl')

circuit1.h(qr1[0])
circuit1.draw(output='mpl')

circuit1.cx(qr1[0],qr1[1])
circuit1.draw(output='mpl')

circuit1.measure(qr1,cr1)
circuit1.draw(output='mpl')

simulator = Aer.get_backend('qasm_simulator')
result1 = execute(circuit1,backend=simulator).result()
plot_histogram(result1.get_counts())

qr2 = QuantumRegister(2)
cr2 = ClassicalRegister(2)
circuit2 = QuantumCircuit(qr2,cr2)
circuit2.draw(output='mpl')

circuit2.h(qr2[0])
circuit2.x(qr2[1])
circuit2.draw(output='mpl')

circuit2.cx(control_qubit=qr2[0],target_qubit=qr2[1])
circuit2.draw(output='mpl')

circuit2.measure(qr2,cr2)
circuit2.draw(output='mpl')

result2 = execute(circuit2,backend=simulator).result()
plot_histogram(result2.get_counts())