Problem related to I.10 codebook section

Hi everyone, what exactly is the difference between below two codes. The only difference I think is that the Code 1 is working for some range of shot values but code Code 2 is working for some default values of some shots.
The Code 1 explanation says that as we increase the values of shots, we reaches close to exact values that are obtained by Code 2. I really do not understand this concept.

# Code 1
#-----------
# An array to store your results
shot_results = []

# Different numbers of shots
shot_values = [100, 1000, 10000, 100000, 1000000]

for shots in shot_values: 
   
    # CREATE A DEVICE, CREATE A QNODE, AND RUN IT
    dev = qml.device('default.qubit', wires=1, shots= shots)
    
    @qml.qnode(dev)
    def circuit():
        qml.RX(np.pi/4, wires=0)
        qml.Hadamard(wires=0)
        qml.PauliZ(wires=0)

        return qml.expval(qml.PauliY(wires=0))

    
    result= circuit()
    shot_results.append(result)
# Code 1
#-----------
dev = qml.device('default.qubit', wires=1)

@qml.qnode(dev)
def circuit():


    # IMPLEMENT THE CIRCUIT IN THE PICTURE AND MEASURE PAULI Y
    
    qml.RX(np.pi/4, wires=0)
    qml.Hadamard(wires=0)
    qml.PauliZ(wires=0)

    return qml.expval(qml.PauliY(wires=0))

print(circuit())

Hello @Manu_Chaudhary ! Since you are working with a simulator, you can calculate the exact value of the wave function without having to run different shots, just multiplying matrices. Not indicating the number of shots means that you want the analytical solution (this will not be possible with a real quantum computer)

I hope that helps :slight_smile: