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

原文链接:Syracuse Sequence Generator

© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容