#!/usr/bin/env python #syracuse.py #a program that runs the syracuse on a number input by the user # written by ALT 2008 from graphics import * def syracuse(win, x): y = 30 while x != 1: if x % 2 == 0: x = x/ 2 y = y + 1 blip = Circle(Point(x, y), x/10) blip.setOutline('white') blip.setFill('white') blip.draw(win) else: x = 3 * x + 1 y = y + 1 blip = Circle(Point(x, y), x/10) blip.setOutline('white') blip.setFill('red') blip.draw(win) def main(): win = GraphWin("Syracuse", 600, 600) win.setBackground('black') win.setCoords(0, 0, 100, 100) print "A program that runs a number through the Syracuse Sequence.\n" x = input("Enter a natural number: ") while x != "": syracuse(win, x) x = input("Enter another natural number: ") win.close() if __name__ == '__main__': main()