Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import combinations_with_replacement
- operatorCnt = 0
- print("enter your calculation with ? for the unknown operators")
- instr = input()
- print("enter the solution")
- solution = input()
- print("your input was:",instr, "=", solution)
- for char in instr:
- if char == '?':
- operatorCnt += 1
- possibleOperators = combinations_with_replacement('+-*/', operatorCnt )
- for combination in possibleOperators:
- i = 0
- teststr = ""
- for char in instr:
- if char == '?':
- teststr += combination[i]
- i += 1
- else:
- teststr += char
- if eval(teststr) == float(solution):
- print("Found solution", teststr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement