Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- for y in range(0, 100):
- res = []
- leng = random.choice(range(3, 16, 2))
- opened = 0
- for t in range(leng):
- if t % 2 == 0:
- if t == 0 or res[-1] == '(':
- res += [random.randint(-100, 100)]
- else:
- res += [random.randint(0, 100)]
- else:
- if opened > 0 and random.randint(0, 100) > 60:
- res += ')'
- opened -= 1
- if t != leng - 1:
- res += random.choice(['-', '+', '*', '/'])
- continue
- res += random.choice(['-', '+', '*', '/'])
- if opened == 0 and random.randint(0, 100) > 70:
- res += '('
- opened += 1
- for t in range(opened):
- res += ')'
- for i in res:
- print(i, end='')
- print()
Add Comment
Please, Sign In to add comment