Advertisement
AceScottie

X*Y=6 X+Y=6

Apr 18th, 2019
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. import time, threading
  2. success = []
  3.  
  4. def add(A, B):
  5.     return "{0:.5f}".format(round(A+B,2))
  6. def mul(A, B):
  7.     return "{0:.5f}".format(round(A*B,2))
  8. def test(A, B):
  9.     if(add(A, B) == 6.0 and mul(A, B) == 6.0):
  10.         return True
  11.     else:
  12.         return False
  13. def threader(A):
  14.     global success
  15.     B = 6.0
  16.     while B > 3.0:
  17.         try:
  18.             if test(A, B):
  19.                 print("Found Match: %s : %s" %(A, B))
  20.                 success.append([A, B])
  21.                 break
  22.             else:
  23.                 B-=0.001
  24.         except KeyboardInterrupt:
  25.             print("stopping")
  26.     print("Thread A=%s has finished"%A)
  27.        
  28. def main():
  29.     A = 0.0
  30.     while A < 3.0:
  31.         A+=0.001
  32.         print("Starting Thread with A as %s" %A)
  33.         t=threading.Thread(target=threader,args=(A,))
  34.         t.start()
  35.     t.join()
  36.     print(success)
  37.  
  38. if __name__ == "__main__":
  39.     try:
  40.         main()
  41.     except Exception as err:
  42.         print("There was an Error:")
  43.         print(err)
  44.         print(success)
  45.     except KeyboardInterrupt:
  46.         print("stopping")
  47.         print(success)
  48.     except:
  49.         print("Something went Wrong")
  50.         print(success)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement