Issue
I don't know why it is not working there are no errors or warnings it was suppossed to multiply by 3 and add 1 if the number in odd and if the number is even it is supposed to divide by 2 until it reaches 0 here is my code any help will be appreciated
num = 4
while num != 0:
if num % 2 == 1:
num = (num * 3) + 1
else:
num /= 2
Solution
Your loop wil run indefinitely because num wil never be 0. I think you want num != 1
. look at this wikipedia page https://en.wikipedia.org/wiki/Collatz_conjecture, And specificly the picture, you can see that 0 is never reached.
Answered By - Robin Dillen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.