-2

My code is the following

output_even = "Even: "
output_odd = "Odd: "

if varnum % 2 == 0:
 varnum /= 2
 print(output_even, varnum)
 time.sleep(0.1)
elif varnum % 2 != 0:
 varnum *= 3
 varnum += 1
 print(output_odd, varnum)
 time.sleep(0.1)

Output (integer 5):

Odd: 16

Even: 8.0

Even: 4.0

Even: 2.0

Even: 1.0

Conjecture not solved

I know that one should not be an even number. But for some reason, it is listed as an even number as shown by the output with the original number being 5.

Edit: Full loop with code for extra clarification hopefully

        while varnum != 1:
            if varnum % 2 == 0:
                print(output_even, varnum)
                varnum /= 2
                time.sleep(0.1)
            elif varnum % 2 != 0:
                print(output_odd, varnum)
                varnum *= 3
                varnum += 1
                time.sleep(0.1)
        if varnum == 1:
            print("Conjecture not solved")
        else:
            print("Conjecture solved")
Quantum
  • 1
  • 4
  • I think your code is missing the enclosing looping syntax that somehow repeatedly runs this code. Cloud you include that, too? – theoctober19th Feb 10 '22 at 03:18

1 Answers1

0

2 is even, though.

You're dividing varnum by 2 and then printing the result of that division.

Try swapping the arithmetic and printing operations.

Levi Ramsey
  • 18,884
  • 1
  • 16
  • 30
  • I will try this, but I just want to learn a little as well so, by doing the arithmetic and then printing it I am printing "odd" or "even" on the previous integer, not the one following the output_even or output_odd in the print statement? – Quantum Feb 10 '22 at 03:19
  • It's similar in the odd case, where you output that 16 is odd (because 5 is odd). – Levi Ramsey Feb 10 '22 at 03:20
  • Yeah that's basically what's happening: you decide `varnum` is odd because `varnum` had the value 5. Then you triple it and add 1 (yielding 16) so you print that 16 is odd. – Levi Ramsey Feb 10 '22 at 03:35
  • I see that makes more sense. Thank you so much :) My code is now working! – Quantum Feb 10 '22 at 03:43