pip install qiskit

pip install qiskit_aer

from qiskit import QuantumCircuit

def deustch_func(value):
    c = QuantumCircuit(2)
    if value in [2,3]:
       c.cx(0,1)
    if value in [3,4]:
       c.x(1)
    return c


num = 2
deustch_func(num).draw()

def deustch_algorithm(func):
    n = func.num_qubits - 1
    qc = QuantumCircuit(n+1,n)

    qc.x(n)
    qc.h(range(n+1))
    qc.barrier()

    qc.compose(func, inplace=True)
    qc.barrier()

    qc.h(range(n))
    qc.measure(range(n),range(n))

    return qc

deustch_algorithm(deustch_func(2)).draw()

from qiskit_aer import AerSimulator

def execute_deutsch(function):
    qc = deustch_algorithm(function)
    result = AerSimulator().run(qc,shots=1,memory=True).result()
    measurements = result.get_memory()
    if measurements[0] == '0':
        return "constant"
    return "balanced"

f = deustch_func(2)
display(f.draw())
execute_deutsch(f)