Ich habe es ein wenig repariert, aber es ist immer noch abgelaufen ...
import random plus, minus = map(int,input().split())
Equal = ["=" for i in range(plus+minus)] Plus = ["+" for i in range(plus+minus)] Minus = ["-" for i in range(plus+minus)]
ok_list_plus = []
ok_list_minus = []
ans_list = []
for i,(p, m, e) in enumerate(zip(Plus, Minus, Equal)): if i < plus: for i in range(5050): if len(ok_list_plus)<(plus): x = random.randint(0,100) y = random.randint(0,100) if x + y < 100 and x - y >= 0: ok_list_plus.append(x) ans1 = (str(x) + " " + str(p) + " " + str(y) + " " + str(e)) if ans1 in ans_list: plus += 1 else: ans_list.append(ans1)
else:
for i in range(5050):
if len(ok_list_minus)<(minus):
x = random.randint(0,100)
y = random.randint(0,100)
if x + y < 100 and x - y >= 0:
ok_list_minus.append(x)
ans2 = (str(x) + " " + str(m) + " " + str(y) + " " + str(e))
if ans2 in ans_list:
minus += 1
else:
ans_list.append(ans2)
for i in ans_list: print(i)
Recommended Posts