# python数字游戏，让你欲罢不能

Python 游戏 不能 数字 欲罢不能

``````for i in range(1,101):
if i%7==0 or '7' in str(i):
print('pass')
else:
print(i)
``````

``````import random
secret = random.randint(1,300)
high = 300
low=0
count=0
while 1:
guess = int((low+high)/2)
count+=1
if guess>secret:
high=guess
elif guess<secret:
low=guess
elif guess == secret:
print('这个数字是：',guess)
print('猜了几次：',count)
break
``````

``````import itertools
import numpy as np
nums=[p for p in itertools.permutations(range(1,10),3) if sum(p)==15] #在全排列中取出所有和为15的组合
for row1_1,row1_2,row1_3 in nums:
for row2_1, row2_2, row2_3 in nums:
for row3_1, row3_2, row3_3 in nums:
if row1_1+row1_2+row1_3==15 \
and row2_1+row2_2+row2_3==15 \
and row1_1+row2_1+row3_1==15 \
and row1_2+row2_2+row3_2==15 \
and row1_1+row2_2+row3_3==15 \
and row1_3+row2_2+row3_1==15:
row1=row1_1,row1_2,row1_3
row2=row2_1,row2_2,row2_3
row3=row3_1,row3_2,row3_3
if len(set(row1)&set(row2))== 0:
matrix=[row1,row2,row3]
print(matrix)
``````

``````p=list(p for p in itertools.permutations(range(1,10),9) if sum([p[0],p[1],p[2]])==sum([p[3],p[4],p[5]])==15 \
and sum([p[0],p[3],p[6]])==sum([p[1],p[4],p[7]])==15 and sum([p[0],p[8]])==sum([p[2],p[6]]))
#print(p)
``````

https://blog.csdn.net/zihong525/article/details/121542401