Skip to content

Input for user choose his Collatz sequence #5080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions maths/collatz_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ def collatz_sequence(n: int) -> list[int]:
obtained as follows:
If n term is even, the next term is: n / 2 .
If n is odd, the next term is: 3 * n + 1.

The conjecture states the sequence will always reach 1 for any starting value n.
Example:
>>> collatz_sequence(2.1)
Expand All @@ -34,10 +33,10 @@ def collatz_sequence(n: int) -> list[int]:


def main():
n = 43
n = int(input("Your number: "))
sequence = collatz_sequence(n)
print(sequence)
print(f"collatz sequence from {n} took {len(sequence)} steps.")
print(f"Collatz sequence from {n} took {len(sequence)} steps.")


if __name__ == "__main__":
Expand Down