shiroi
scidamспасибо большое, если я правильно понял, то функция product возвращает нам все возможные комбинации введенной нами последовательности?а что делает вот эта часть
Это чтобы не писать 8 аргументов функции product, т.е. вместо этого:
product(['+', '-', ''],['+', '-', ''], repeat this 8 times)
Далее, нужен цикл по всем возможным комбинациям, возвращаемым product, т.е.
for combination in product(...):
expression = ... # Here we need to construct the expression to be evaluated: e.g. use ''.join(...) and list comprehension concept
answer = ast.literal_eval(expression) # tested in Python 3.5.x, import ast first!
if anser == number: # compare the result and the target value
print('Target expression is: ', expression)
break
else: #see for-else docs for details...
print('Sorry... Target expression wasn't found.')