Advertisement
Guest User

Collatz counter

a guest
Jun 14th, 2019
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. print('Enter value please:')
  2. value=input()
  3. value=int(value)
  4. spam=0
  5. while value != 1:
  6. if value%2 == 0:
  7. print (value/2)
  8. value=int(value/2)
  9. spam=spam+1
  10. elif value%2 != 0:
  11. print(3*value+1)
  12. value=int(3*value+1)
  13. spam=spam+1
  14. #end the sequence if 1 is achieved and report results
  15. if value == 1:
  16. spam=str(spam)
  17. print ('Reduction complete.')
  18. print ('This value required '+spam+' steps.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement