Python Conjecture
<p>recently I have been trying to make a spin-off of Collatz conjecture using python 3.0. The program works as it should with positive integers, but it will not work with negative integers. In the program I check if the number is negative and if so I square it, and then proceed with collatz, rules. Unfortuanitly it gives off no error messages. Code below:</p>

<pre><code> import sys

 while True:
    number = input("Enter any positive integer: ")
    count = 0
    negative = "-"
    try:
        int(number)
    except ValueError:
        print("Invalid Input...")
        sys.exit(0)
    else:
       number = int(number)
        ORIGINAL = number
    while not number != 1:
        count += 1
        number ** 2
        if number % 2:
            number = 3*number+1
        elif not number % 2:
            number = number // 2
        print(number)
    while number != 1:
        count += 1
        if number % 2:
            number = 3*number+1
        elif not number % 2:
            number = number // 2
        print(number)

    print("The number "+str(ORIGINAL)+" took "+str(count)+" calculations to reach 1")
</code></pre>

<p>feel free to try out my code, it only uses python 3 and sys!</p>

<p>-thanks!</p>

<p>In the mapping used by the Collatz conjecture, a positive value always maps to another positive value. So you only need to check for negative values as part of your initialisation:</p>

<pre><code>number = input("Enter any integer: ")
count = 0
try:
    number = int(number)
except ValueError:
    print("Invalid Input...")
    sys.exit(0)
if number &lt; 0:
    number = number ** 2
</code></pre>

<p>The loop <code>while not number != 1:</code> can be deleted. It will only run if number is equal to 1 (there is a double negative). If you enter 1, this loop will run once, assign 3*1+1 to number, and then the second loop will start. In other words, this loop is pointless: delete it.  Note the line <code>number ** 2</code> will not change the value of number, since there is no assignment.</p>

python python-3.x sys