import random
from itertools import count
import numpy as np
w=np.array(random.sample(range(1,10),1))
x=np.array(random.sample(range(1,10),1))
y=np.array(random.sample(range(1,10),1))
z=np.array(random.sample(range(1,10),1))
A=w[0]+x[0]+y[0]+z[0]print(x)for x in count():if A==9:break
w = np.array(random.sample(range(1,10),1))
x = np.array(random.sample(range(1,10),1))
y = np.array(random.sample(range(1,10),1))
z = np.array(random.sample(range(1,10),1))
A = w[0]+x[0]+y[0]+z[0]print(x)
运行结果:
C:\Users\10673\Scripts\python.exe C:\Users\10673\Desktop\GA\Test.py
[7]232
Process finished with exit code 0