I.1.3 None is not iterable

I’m getting an error that says None is not iterable. I’m pretty new to python so I might not understand what’s going on. Is it something wrong with the indexing of state? Thanks

if state is not None:
x=np.abs(state[0])**2

    y=np.abs(state[1])**2

    p1=np.real(x)
    p2=np.real(y)

    probs=np.array([p1,p2])
# COMPUTE THE MEASUREMENT OUTCOME PROBABILITIES

# RETURN A LIST OF SAMPLE MEASUREMENT OUTCOMES
    arr=np.array([0,1])
    array=np.random.choice(arr,size=num_meas,replace=True,p=probs)

Sorry for posting then solving my own questions. But I reset the code and tried coding it again this way. I don’t know what’s different but it worked:

arr = np.array([0,1])
# COMPUTE THE MEASUREMENT OUTCOME PROBABILITIES
x = np.square(np.abs(state[0]))
y = np.square(np.abs(state[1]))

p1 = np.real(x)
p2 = np.real(y)
probs=np.array([p1,p2])
# RETURN A LIST OF SAMPLE MEASUREMENT OUTCOMES
return np.random.choice(arr,size=num_meas,p=probs)

Hi @Jack1,

Did you remember to return the array you got from your first code? :wink:

You can try the codercise again with your first code to see if it works now!