Quantcast
Channel: Python - The Collatz Sequence - Code Review Stack Exchange
Browsing all 4 articles
Browse latest View live

Answer by DeepSpace for Python - The Collatz Sequence

For sake of completeness, a recursive implementation for collatz (you already got enough good suggestions for inputting num):def collatz(num): print(num) if num == 1: return num if num % 2 == 0: return...

View Article



Answer by 200_success for Python - The Collatz Sequence

PromptThe most obvious bad practice here is the use of a global variable. Instead of setting num as a side-effect, your function should return the result.getNum() is not such a good name for the...

View Article

Answer by Carcigenicate for Python - The Collatz Sequence

First, note how you're duplicating calculations:print(num//2)num = num //2This may not cause issues with this specific code, but it isn't a good practice. You're doing twice as much work as you need...

View Article

Python - The Collatz Sequence

Can I get a review of my code for the the Collatz Sequence from Chapter three of Automate the Boring Stuff with Python?The Collatz SequenceWrite a function named collatz() that has one parameter named...

View Article
Browsing all 4 articles
Browse latest View live




Latest Images