Timeline for Python - The Collatz Sequence
Current License: CC BY-SA 4.0
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 20, 2019 at 18:25 | comment | added | cyberprogrammer | @200_success Thanks for pointing out my failure to return the number not simply print it. That was very helpful. | |
| Sep 19, 2019 at 9:01 | comment | added | Gloweye | While technically you could use if num % 2 else, I agree that showing the intent here is more important. and if num % 2 == 0 else communicates that intent better. I do agree you should rename your next variable, though. It's a bad habit. | |
| Sep 19, 2019 at 8:16 | comment | added | DeepSpace | next = ... overshadows the built-in next. In this context it's probably not hazardous, but just good to be aware of | |
| Sep 19, 2019 at 1:02 | comment | added | Carcigenicate | @RootTwo Honestly, I find that that muddies the intent. We're not checking if num % 2 is falsey; it's not a predicate. We're checking if it's equal to 0. It just so happens that they're equivalent in Python. | |
| Sep 18, 2019 at 23:04 | comment | added | RootTwo | Perhaps reverse the test and eliminate the comparison to 0: next = 3 * num + 1 if num % 2 else num // 2 | |
| Sep 18, 2019 at 22:14 | history | answered | 200_success | CC BY-SA 4.0 |