我正在尝试创建一个玩游戏的循环。
我想匹配如果元组返回所提供的值,则结果应为供认或不承认。让我们称他们的回报。但是在以下测试代码中,它返回(0,0)作为供认,原始列表中未返回供认。
Dont confess: (-1, -1)
Confess : (-10, 0)
Confess : (0, -10)
Dont Confess: (-10, -10)
dntCon=(-1, -1)
conf=(-10, 0)
confess=(0, -10)
DntConff=(-5, -5)
import random
from random import shuffle
from random import sample
x = [-1, -10, 0, -5]
y = [-1, 0, -10, -5]
#print(sample(list, len(list)))
for m in range(0, 3):
x=random.sample(x, len(x))
y=random.sample(y, len(y))
#print(x, y)
for i in x:
#print(i)
for j in y:
#print(i, j)
if(i ==-1 & j==-1 ):
print(i, j, "ncoo")
#print( i, j,'')
elif (i==-10 & j==0):
print(i, j, 'Confess')
elif (i==0 & j==-10):
print(i, j, 'Confess')
elif (i==-10 & j==-10):
print(i, j, 'ncoo')
else:
"not met"
结果
(0, 0, 'Confess')
(-10, -10, 'ncoo')
(-10, -1, 'ncoo')
(-1, -1, 'ncoo')
(0, 0, 'Confess')
(-10, -10, 'ncoo')
(-10, -1, 'ncoo')
(-1, -1, 'ncoo')
(-10, -1, 'ncoo')
(-10, -10, 'ncoo')
(-1, -1, 'ncoo')
(0, 0, 'Confess')
为什么这个循环返回(0, 0
)作为不符合我的标准的供认
在Python中,'&和'和'。请参阅此链接,以查看"和(布尔)与'&'之间的差异(位)在Python中。为什么列表与Numpy数组的行为差异?尝试此代码:
Dont_confess: (-1, -1)
Confess : (-10, 0)
Confess : (0, -10)
DontConfess: (-10, -10)
dntCon=(-1, -1)
conf=(-10, 0)
confess=(0, -10)
DntConff=(-5, -5)
import random
from random import shuffle
from random import sample
x = [-1, -10, 0, -5]
y = [-1, 0, -10, -5]
#print(sample(list, len(list)))
for m in range(0, 3):
x=random.sample(x, len(x))
y=random.sample(y, len(y))
#print(x, y)
for i in x:
#print(i)
for j in y:
#print(i, j)
if(i ==-1 and j==-1 ):
print(i, j, "ncoo")
#print( i, j,'')
elif (i==-10 and j==0):
print(i, j, 'Confess')
elif (i==0 and j==-10):
print(i, j, 'Confess')
elif (i==-10 and j==-10):
print(i, j, 'ncoo')
else:
"not met"