Почему происходит только одна итерация цикла?
Код:
import random
def dividers(n):
zero = n
i = 2
dividers = set()
while i**2 <= n:
while n % i == 0:
dividers.add(i)
n = n / i
i = i + 1
if n > 1:
dividers.add(int(n))
dividers.discard(zero)
return dividers
def newexpression(length, eoperators=None, extra=None):
nums = []
expression = ""
while len(expression) <= length:
if expression != "" and expression[-1] == "/":
num = random.choice(numdividers)
expression += num
else:
num = random.choice("123456789")
expression += num
if (random.choice([True, False]) == True or len(expression) == length - 1) and length != 1:
num = num + random.choice("0123456789")
expression += num[1:]
numdividers = dividers(int(num))
if len(expression) < length and eoperators != None:
if "/" in eoperators and numdividers != set():
expression = expression + random.choice(eoperators)
elif "/" not in eoperators:
expression = expression + random.choice(eoperators)
else:
expression = expression + random.choice(eoperators[:-1])
print(expression)
return expression
print(newexpression(6, "+-"))
Цикл, о котором идёт речь:
while len(expression) <= length:
if expression != "" and expression[-1] == "/":
num = random.choice(numdividers)
expression += num
else:
num = random.choice("123456789")
expression += num
if (random.choice([True, False]) == True or len(expression) == length - 1) and length != 1:
num = num + random.choice("0123456789")
expression += num[1:]
numdividers = dividers(int(num))
if len(expression) < length and eoperators != None:
if "/" in eoperators and numdividers != set():
expression = expression + random.choice(eoperators)
elif "/" not in eoperators:
expression = expression + random.choice(eoperators)
else:
expression = expression + random.choice(eoperators[:-1])
print(expression)
Я не понимаю