There are several IDEs available for python, which is based on user choice and preferences. For instance, much data scientist or related persons use the so-called Jupyter Notebook which comes with the anaconda distribution.
Now, Jupyter Notebook will show the output in-line of the last statement/code executed (if there is something to print) without actually providing a print(var)
statement. But, this is not the case for many other IDEs or if you run the code from terminal/command prompt - there you must add print(XYZ())
, as commented previously. Hope this answered your question!
Coming to coding prespective, I don't see any point of making your code so complicated just to do a "simple factorial" of a number. This can be achieved by just using a single line of code:
import math
def factorial(n):
return math.prod(list(range(n, 0, -1)))
print(factorial(n = int(input("Enter a Number:"))))
There are several reasons for this:
- It is better to keep your input/arguments outside your function. This gives you more control.
- Using inbuilt basic tools like
math
or os
etc. makes your code much faster.
- If you still want to go for functions without using a single library, you can include your summation within a single function.