尝试一下
- import random
- numbers =[i for i in range(1,10)]
- a,b,c,d,e,f,g,h = (random.choice(numbers) for i in range(8))
- if a+b==9 and b+c==8 and c+d==14 and d+e==11 and e+f==3 and f+g==3 and g+h==9 and h+a==13:
- print(f"正确:{a}{b}{c}{d}{e}{f}{g}{h}")
- else:
- print("不正确")
-
- count=0
- while True:
- count+=1
- if e+f==3 and f+g==3 and d+e==11:
- print(e,f,g,d)
- if d+c==14:
- print(d,c)
- if c+b==8:
- print(c)
- if a+b==9:
- print(a,b)
- if g+h==9 and a+h==13:
- print(a,b,c,g,h)
- break
- else:
- h=random.choice([1,2,3,4,5,6,7,8,9])
- else:
- a=random.choice([1,2,3,4,5,6,7,8,9])
- else:
- b=random.choice([1,2,3,4,5,6,7,8,9])
-
- else:
- c=random.choice([1,2,3,4,5,6,7,8,9])
- else:
- e=random.choice([1,2])
- f=random.choice([1,2])
- g=random.choice([1,2,3,4,5,6,7,8,9])
- d=random.choice([1,2,3,4,5,6,7,8,9])
-
- if a+b==9 and b+c==8 and c+d==14 and d+e==11 and e+f==3 and f+g==3 and g+h==9 and h+a==13:
- print(f"正确:{a}{b}{c}{d}{e}{f}{g}{h}")
- print(count)
- else:
- print("不正确")
复制代码 |