#Python Collatz Conjecture Exercise: Tests Getting Timed Out

5 messages · Page 1 of 1 (latest)

rancid badge
#

As in title , my tests are getting timed out. Even though the code works.

Code:

def steps(number):
    steps=0
    if number<0:
        raise Exception("Only Positive Numbers allowed")

    while number!=1:
        if number%2==0:
            number= number/2
            steps+=1 
        else:
            number=3*(number)+1
            steps+=1
            
    print(steps)
orchid ridge
#

What happens if number equals zero?

zenith dew
#

Whenever you have a while loop and encounter a timed out on the website, double check to make sure you are not stuck in an indefinitely loop.

rancid badge
#

oh okay, ill modify code to include 0 and check if there is any other response

#

It worked, i guess i had to include 0 and fix the error message.