Collatz conjecture tester (only prints results)


/ Published in: Python
Save to your folder(s)

Try it out in a python interpreter!


Copy this code and paste it in your HTML
  1. def mathprob_no_print(x):
  2. string2 = str(x)
  3. while x != 1:
  4. if x % 2 == 0:
  5. x = x/2
  6. else:
  7. x = 3 * x + 1
  8. if x == 1:
  9. return string2+" was a failure"
  10. else:
  11. return string2+" passed the test!"
  12.  
  13.  
  14.  
  15. def math_repeat(x,p):
  16. while x <= p:
  17. print mathprob_no_print(x)
  18. x = x + 1
  19.  
  20. math_repeat(1,100)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.