-1

I am writing a script in python:

import random
import numpy as np
from operator import itemgetter
equal_to = {"a":"u_plus", "b":"u_minus", "c":"v_plus", "d":"v_minus"} #bell state
count = 0 #count until b is found
count1 = 0 #count for nested loop

p = 8 #length of generated binary
key1 = [] #list of generated binary 
for i in range(p): 
    temp = random.randint(0,1)
    key1.append(temp) 

tmplist2 = [] #list of random sample_letters
while True:
    attempt = str(random.choice(list(equal_to)))
    tmplist2.append(attempt)

    if attempt == 'b':
        break

    count += 1

#evaluate result of alice binary and bell state
def eval(alice, bell):
    if alice == 1:
        if bell == 'a' or 'b':
            return 1
        elif bell == 'c' or 'd':
            return 0
    elif alice == 0:
        if bell == 'c' or 'd':
            return 1
        elif bell == 'a' or 'b':
            return 0
for_bob = [] #list of generated binary and bell state through logic gate
for k in key1:
    for t in tmplist2:
        e = eval(k, t)
        for_bob.append(e)
    count1 += 1
#tr = [[eval(k,t) for t in tmplist2] for k in key1] #list comprehension split the key properly
print("generated random binary strings:", key1)
print("generated bell states:", tmplist2)
**print(for_bob)**

at the very last line print(for_bob), it only printed 1 although I put it as parameter of function eval() (see third block). It should print either 1 or 0 the condition of alice and bell is equal to given conditon. Is there any mistake with my code?

Aniket Tiratkar
  • 798
  • 6
  • 16

1 Answers1

0

paste this in your eval and its should solve your problem

#evaluate result of alice binary and bell state
def eval(alice, bell):
    if alice == 1:
        if bell == 'a' or bell == 'b':
            return 1
        elif bell == 'c' or bell == 'd':
            return 0
    elif alice == 0:
        if bell == 'c' or bell == 'd':
            return 1
        elif bell == 'a' or bell == 'b':
            return 0

the 'or' is like countinue to test the variable , not the value
so You need just add the variable bell == before the second argument

Amirul Akmal
  • 401
  • 6
  • 13