Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- rn = re.compile(r'^[0-9]+$')
- num = raw_input("Enter a natural number: ")
- while not rn.match(num):
- num = raw_input("Enter a natural number: ")
- num = int(num)
- while num != 1:
- print num
- if (num % 2):
- num = 3 * num + 1
- else:
- num /= 2
- print num
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement