!pip install qiskit

!pip install pylatexenc

import qiskit
import pylatexenc

from qiskit import *
from pylatexenc import *

qr= QuantumRegister(2)
#quantum register is a system comprising multiple qubits

cr= ClassicalRegister(2)

circuit = QuantumCircuit(qr,cr)

%matplotlib inline

import matplotlib.pyplot as plt

circuit.draw(initial_state = True)

circuit.h(qr[0])
#applying handmard gate

circuit.draw(output='mpl',initial_state = True)

#logical if
circuit.cx(qr[0],qr[1])

circuit.draw(output='mpl')

circuit.measure(qr,cr)
#measure quantum bits and take those measurements and store in classical bits

circuit.draw(output='mpl',initial_state = True)

simulator = Aer.get_backend('qasm_simulator')

result= execute(circuit,backend=simulator).result()

from qiskit.tools.visualization import plot_histogram

print(result.get_counts(circuit))
#These outcomes correspond to the basis states |00⟩, |01⟩, |10⟩, and |11⟩, respectively.

counts = result.get_counts(circuit)
total_shots = sum(counts.values())

# Calculate the probabilities
probabilities = {state: count / total_shots for state, count in counts.items()}

plot_histogram(probabilities)

