n = raw_input("Enter an integer") def factorial(x): x = int(x) total = 1 while x>0: total *= x x-=1 return total factorial(n)
you have an infinity loop,
x is not decreased within the loop
You should perform the conversion of the user’s input prior to calling the function.
Why are you not displaying the result of the function call?
I believe you are providing to much code. The excersice asks to define a function nothing more.
def factorial(x): x = int(x) #not sure if this line is even needed total = 1 while x > 0: total *= x x-=1 return total
Why is x not decreasing? It’s part of the loop
no, its not. here is a screenshot of your code:
Still doesn’t work with this code. Copy/paste indents it in a way that isn’t consistent with what’s actually on the page. I recommend viewing the link too, thanks.
n = int(raw_input("Enter an integer")) def factorial(x): total = 1 while x>0: total *= x x-=1 return total factorial(n)
I wanted to see if I could mod the code to have a raw_input, but I’m wondering why it doesn’t work.
what if you run your code on repl? Could be the exercise validation doesn’t like the use of raw_input.
Okay well it seems to work now on that site, thanks.