DEV Community

Cover image for Syracuse Sequence Generator
Scott Gordon
Scott Gordon

Posted on

Syracuse Sequence Generator

# syracuse_sequence.py
#   This program generates the syracuse sequence by starting with a
#   natural number and repeat the function til it reaches 1
# by: Scott Gordon

def main():
    print("Welcome to Syracuse Sequence Generator\n")
    num = int(input("Enter initial value (int >= 1): "))
    while num != 1:
        print(num, end=' ')
        if num % 2 == 0:
            num = num / 2
        else:
            num = 3 * num + 1
    print(1) 

if __name__ == '__main__':
    main()

Enter fullscreen mode Exit fullscreen mode

Photo by Bradyn Trollip on Unsplash

Top comments (0)