Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (anonymous):

Trouble writing loops for 3n+1 problem. Anyone with a clue?

OpenStudy (anonymous):

Let me try this code fun(n) while n > 1 show n if n is odd then set n = 3n + 1 else set n = n / 2 endif endwhile show n

OpenStudy (anonymous):

That works. If you like a recursive version, try with: def fun(n): print n if n is 1: return if n is odd: n = 3n + 1 else: n = n/2 fun(n)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!