[Tutor] Executing from Python prompt

Alan Gauld alan.gauld at btinternet.com
Sat Apr 19 23:21:22 CEST 2008

"kinuthia muchane" <muchanek at gmail.com> wrote

> I do not know what I am doing wrong. When I run the following code 
> from
> the Python prompt it executes without a murmur. But when I save it 
> as
> a .py file and try to execute it from the shell, it just returns the
> prompt...actually it is all scripts that return a value which  are
> behaving in this manner.

The >>> prompt evaluates expressions and prionts the value.
The interpreter on the other hand does not automatically print
values you ghave to explicitly tell it to print using the print

So in your case just add the print command in front of the
function call and all will be well.

> factorial(some number here)

print factorial(n)


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list