Lesnic

generator

Jul 13th, 2021 (edited)
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. import random
  2.  
  3. for y in range(0, 100):
  4.     res = []
  5.     leng = random.choice(range(3, 16, 2))
  6.     opened = 0
  7.     for t in range(leng):
  8.         if t % 2 == 0:
  9.             if t == 0 or res[-1] == '(':
  10.                 res += [random.randint(-100, 100)]
  11.             else:
  12.                 res += [random.randint(0, 100)]
  13.         else:
  14.             if opened > 0 and random.randint(0, 100) > 60:
  15.                 res += ')'
  16.                 opened -= 1
  17.                 if t != leng - 1:
  18.                     res += random.choice(['-', '+', '*', '/'])
  19.                 continue
  20.  
  21.             res += random.choice(['-', '+', '*', '/'])
  22.             if opened == 0 and random.randint(0, 100) > 70:
  23.                 res += '('
  24.                 opened += 1
  25.  
  26.     for t in range(opened):
  27.         res += ')'
  28.     for i in res:
  29.         print(i, end='')
  30.     print()
  31.  
Add Comment
Please, Sign In to add comment