Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. from itertools import combinations_with_replacement
  2.  
  3. operatorCnt = 0
  4. print("enter your calculation with ? for the unknown operators")
  5. instr = input()
  6. print("enter the solution")
  7. solution = input()
  8. print("your input was:",instr, "=", solution)
  9.  
  10. for char in instr:
  11. if char == '?':
  12. operatorCnt += 1
  13. possibleOperators = combinations_with_replacement('+-*/', operatorCnt )
  14. for combination in possibleOperators:
  15. i = 0
  16. teststr = ""
  17. for char in instr:
  18. if char == '?':
  19. teststr += combination[i]
  20. i += 1
  21. else:
  22. teststr += char
  23. if eval(teststr) == float(solution):
  24. print("Found solution", teststr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement