Using While


#1



Find the Factorial using 'while' loop


Following one is the error message I'm getting.
"Oops, try again. factorial(4) returned 12 instead of 24"


def factorial(x):
    beep = x
    bloop = 1
    if beep > 1:
        while beep > 1:
            bloop = beep * (beep - 1)
            beep = beep - 1
            return bloop
    elif beep == 1 or beep == 0:
        return bloop


#2

a function ends the moment a return keyword is reached, so your function ends in the first run/iteration of the loop, that can't be right?

bloop never increases? You simply assign a new value to bloop, not adding it to what value is already stored in bloop


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.