I am attempting to make a collatz conjecture program, but I can't figure out how to check for even numbers this is my current code for it
elif (original_collatz % 2) == 0:
new_collatz = collatz/2
anyone have an idea how to check
i tried it with modulo but could figure out how it works, and my program just ignores this line, whole program: `
#collatz program
import time
collatz = 7
original_collatz = collatz
new_collatz = collatz
while True:
if original_collatz % 2 == 1:
new_collatz = (collatz * 3) + 1
elif (original_collatz % 2) == 0:
new_collatz = collatz/2
collatz = new_collatz
print(collatz)
if collatz == 1:
print('woo hoo')
original_collatz += 1
time.sleep(1)
The problem is not that "your program ignore the lines", it's that you test the parity of
original_collatzwhich doesn't change.collatz//) when dividing by two orcollatzwill become a float.new_collatzas an intermediate, you could just overwritecollatzdirectly.Here is a fixed sample: