!pip install qiskit

!pip install pylatexenc

import qiskit
import pylatexenc

from qiskit import *
from pylatexenc import *

# Create a quantum circuit with three qubits
qc = QuantumCircuit(3, 3)

%matplotlib inline

qc.draw(initial_state = True)

# Create a Bell pair between qubits 1 and 2
qc.h(1)
qc.cx(1, 2)
# The Hadamard gate qc.h(1) is applied to qubit 1 to create a superposition, and the CNOT gate qc.cx(1, 2) is applied between qubits 1 and 2 to entangle them and create a Bell pair

qc.draw(initial_state = True)

# Entangle qubit 0 with qubit 1
qc.cx(0, 1)
qc.h(0)

qc.draw(initial_state = True)

# Apply a measurement to qubits 0 and 1
qc.barrier()
qc.measure([0,1], [0,1])

qc.draw(initial_state = True)

# Apply a controlled-X gate to qubits 1 and 2
qc.cx(1, 2)

qc.draw(initial_state = True)

# Apply a controlled-Z gate to qubits 0 and 2
qc.cz(0, 2)

qc.draw(initial_state = True)

# Apply a measurement to qubit 2
qc.measure(2, 2)


qc.draw(initial_state = True)


# Run the circuit on a simulator
backend = Aer.get_backend('qasm_simulator')
result = execute(qc, backend).result()

# Print the result
print(result.get_counts(qc))

