day1/exercise/collatz.py
author Christopher Burns <chris.d.burns@gmail.com>
Sun, 27 Jun 2010 22:05:22 -0500
branchscipy2010
changeset 425 5afcfce15e71
parent 386 a0bec380b44f
permissions -rw-r--r--
REF: Reformat some of the exercises so they're easier to read for the audience.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
425
5afcfce15e71 REF: Reformat some of the exercises so they're easier to read for the audience.
Christopher Burns <chris.d.burns@gmail.com>
parents: 386
diff changeset
     1
num = int( raw_input( 'Enter number: ') )
5afcfce15e71 REF: Reformat some of the exercises so they're easier to read for the audience.
Christopher Burns <chris.d.burns@gmail.com>
parents: 386
diff changeset
     2
while num != 4:
5afcfce15e71 REF: Reformat some of the exercises so they're easier to read for the audience.
Christopher Burns <chris.d.burns@gmail.com>
parents: 386
diff changeset
     3
    print num,
5afcfce15e71 REF: Reformat some of the exercises so they're easier to read for the audience.
Christopher Burns <chris.d.burns@gmail.com>
parents: 386
diff changeset
     4
    if num % 2 == 1:
5afcfce15e71 REF: Reformat some of the exercises so they're easier to read for the audience.
Christopher Burns <chris.d.burns@gmail.com>
parents: 386
diff changeset
     5
        num = num * 3 + 1
64
333092b68926 Added quiz tex file and all exercise problems Madhu worked out.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
    else:
425
5afcfce15e71 REF: Reformat some of the exercises so they're easier to read for the audience.
Christopher Burns <chris.d.burns@gmail.com>
parents: 386
diff changeset
     7
        num /= 2
386
a0bec380b44f Major edits.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 354
diff changeset
     8
print 4, 2, 1