Practice makles perfect 5/15 - not sure what im doing wrong, no hint either


My code:

def factorial(x):
  y = 0
  while x > 1:
    y == x ** (x-1)
  if x <= 1:
    y == 1
  return y

I dont know whats wrong, it doest give me any errors but it wont let me go further. Thanks :slight_smile:


== is for comparison, to check if values are equal, they are commonly used in if conditions for example

you use == at places which doesn’t look right


Thanks but even after changing all the == to = it still doesnt work for some reason :-/


maybe add a function call? and some print statements to see what your code is doing?

what error message do you get?


No error messages, nothing. But i tried resetting my workplace and just printing a statement without any code - nothing happend. So i guess there’s an issue with the website?


did you include a function call? Functions only execute when called

i think i spotted the problem, you have infinity loop, this will cause a crash.


It was an infinite loop. Took me some time but i was finally able to fix it. Yay, thanks for the help!

def factorial(x):
y = 1
while x > 1:
y = y * x
x = x - 1
return y


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