Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The Collatz Sequence
#6
Hello,

I think that in your first iteration you're still comparing a char with an integer. Try to introduce '1' and verify if the execution doesn't enter to the loop. I think that you must do the cast to integer in the input() function and not in the collatz function.

try:
    n = int(input("Give me a number: "))
    while n != 1:
        print(n)
        n = collatz(abs(n))
except ValueError:
    print('Type a number please!')
What do you think?
Reply


Messages In This Thread
The Collatz Sequence - by Truman - Apr-17-2018, 10:54 PM
RE: The Collatz Sequence - by micseydel - Apr-17-2018, 11:10 PM
RE: The Collatz Sequence - by Truman - Apr-18-2018, 10:11 PM
RE: The Collatz Sequence - by mlieqo - Apr-18-2018, 09:29 AM
RE: The Collatz Sequence - by vaison - Apr-18-2018, 01:41 PM
RE: The Collatz Sequence - by vaison - Apr-19-2018, 11:03 AM
RE: The Collatz Sequence - by Truman - Apr-19-2018, 09:38 PM
RE: The Collatz Sequence - by vaison - Apr-19-2018, 10:23 PM
RE: The Collatz Sequence - by Truman - Apr-19-2018, 10:48 PM
RE: The Collatz Sequence - by mlieqo - Apr-20-2018, 08:08 AM
RE: The Collatz Sequence - by s_sahil - Dec-27-2018, 07:19 AM
RE: The Collatz Sequence - by Truman - Dec-27-2018, 11:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Collatz-problem CaptainNeemo 2 2,242 Dec-07-2020, 04:09 PM
Last Post: deanhystad
  How can I found how many numbers are there in a Collatz Sequence that I found? cananb 5 3,835 Nov-23-2020, 05:15 PM
Last Post: cananb
  [split] The Collatz Sequence valencia 4 3,732 Jan-06-2019, 08:10 PM
Last Post: valencia

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020