Code "passes" but doesn't print expected output


#1

x = int(input("Enter a number: "))
def factorial(x):
----digit = 1
----if x < 0:
------print "Sorry, factorial does not exist for \
------negative numbers"
----else:
------for i in range(1, x + 1):
---------digit = digit * i
---------print digit
---------print "The factorial of ",x," is ",digit
------return digit

This seems to pass whatever checker Codecademy uses, but it doesn't actually return any of the print commands. My input works, but then no matter what I put in, I just get Codecademy's "None" output. What have I got screwed up in here?


#2

I was doing an exercise in Python with the print command, and I got "none" as well. I think that it's there in place of the expected output to show that you did the exercise correctly?


#3

I'm sadly glad I'm not the only one with mysterious print fails.

If this is indeed them just overriding the output with 'None', that seems like a rather unfortunate 'feature'.


#4

Here is your code I have commented the changes I made

x = int(input("Enter a number: "))
def factorial(x):
    digit = 1
    if x < 0:
        print "Sorry, factorial does not exist for negative numbers"
    else:
        for i in range(1, x + 1):
            digit = digit * i
            print digit
        print "The factorial of ",x," is ",digit
    return digit

print factorial(x) # You have to call the method before you can see it

Or you can test it out here
factorial playground on labs(click to visit)

In the future when you paste code in the forum try to select it an press ctrl + k or the </> in the tools pane to make it easier to test