Hey everyone!
I’m trying out the Collatz conjecture exercise in python on exercism but when I run my code my session times out. I’m pretty sure I’m stuck in an infinite loop but I’m not sure why as I made sure to put in the condition for the loop to break in my while statement.
I tried putting in an if statement as well in case i made a mistake initally. But it still isn’t working. I have no idea what to do at this point.
I put my code here too in case any clarifications are needed.
def steps(number):
if number < 0:
raise ValueError("Only positive integers are allowed")
steps = 0
while number != 1:
number = (3*number)+1 if number%2 else number/2
steps += 1
if number == 1:
break
return steps
user23090320 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.