Simple Collatz Conjecture (terminal/command prompt)

This is the place to post any code that you want to share with the community. Only completed scripts should be posted here.
Note: posts here are not necessarily endorsed by the community, and may represent amateur or even bad practices.

Simple Collatz Conjecture (terminal/command prompt)

Postby mckryall » Sat Feb 08, 2014 7:57 am

Code: Select all
import time
def odd_even(n):
   return n % 2 == 0

def collatz(n):
   o_e = odd_even(n)
   if o_e == True:
      n = n / 2
   elif o_e == False:
      n = n * 3 + 1
   print n
   return n
def collatzloop(n):
   while n != 1:
      n = collatz(n)
def mainloop():
   n = int(raw_input("What number do you want to start with?\n> "))
   if n == 0:
      print "You broke it, you know that?"
      print "Now, just sit back and wait for the singularity."
   while True:
      while n != 1:
         n = collatz(n)
print "Collatz Conjecture Calculator"
print "Version 1.0"
print "Jan 12 2014\n"
while True:
      while True:
         again = raw_input("Do you want to do this again?\n> ")
         if again.lower() in ['y', 'yes']:
         elif again.lower() in ['n', 'no']:
            print "What? Try \"yes\" or \"no\""
   except KeyboardInterrupt:

Last edited by Mekire on Sat Feb 08, 2014 8:00 am, edited 1 time in total.
Reason: Locked.
Python 2.7
Mac Mini (Desktop/server)
Macbook Air
Laptop w/ Ubuntu 14.04
Posts: 116
Joined: Sat Nov 23, 2013 6:13 pm

Return to Completed Scripts

Who is online

Users browsing this forum: No registered users and 1 guest