Python learning record (paiza B problem: math drill)

I fixed it a little, but it still times out ...

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

Python learning record (paiza B problem: math drill)
Python learning record (paiza: B problem: calculation drill)
Learning record
Learning record # 3
Learning record # 1
python learning
Learning record # 2
[Python] Learning Note 1
Python learning notes
python learning output
Python learning site
Python learning day 4
Python Deep Learning
Python learning (supplement)
Deep learning × Python
Computation drill python
ARC # 008 B problem
python learning notes