Python learning record (paiza: B problem: calculation drill)

The first test passed, but as the test progressed No processing was done due to a timeout.

Task ・ While seems to take time, so rewrite with for ・ Rewrite list creation with comprehension

import random plus, minus = map(int,input().split())

Equal = [] Plus = [] Minus = []

for i in range(plus+minus): Plus.append("+") for i in range(plus+minus): Minus.append("-") for i in range(plus+minus): Equal.append("=") ok_list_plus = []
ok_list_minus = [] ans_list = []

for i,(p, m, e) in enumerate(zip(Plus, Minus, Equal)): if i < plus: while 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:
    
    while 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: calculation drill)
Python learning record (paiza B problem: math drill)
Learning record
Learning record # 3
Learning record # 1
python learning
Learning record # 2
[Python] Learning Note 1
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