[Tutor] Using Python to solve factoria

boB Stepp robertvstepp at gmail.com
Wed Dec 21 14:30:05 EST 2016


On Wed, Dec 21, 2016 at 1:50 AM, Hedgar <ajakzhedgar at gmail.com> wrote:
> Hello,
> I really happy to be accepted to the list!
> This is my current function:
> def factoria(numb):
> While numb > 1:
> If numb==0:
> return 1
> Else:
> result = numb*(numb-1)
> numb = numb -1
> return result
> factoria(5)
> #should output 120
> What am I not getting right?

I'll help you part way.  Firstly Python is case sensitive.  You have
several examples of where you start Python keywords with a capital
letter when it should be lowercase. Secondly Python uses indentation
(Conventionally 4 spaces.) to segregate code blocks.  Thirdly, you
won't see the result of your function if you don't print it.  So if I
correct these in your code I get:

def factoria(numb):
    while numb > 1:
        if numb==0:
            return 1
            result = numb*(numb-1)
            numb = numb -1

        return result


But alas!  There is more work to be done.  This will not give you a
syntax error, but now there is an issue with logic error(s).  Can you
figure it out?  It might help if you pretend you are the computer and
work out the while loop on paper through each iteration until it

Also, when you ask for help you should copy and paste the full
traceback of the error you received.  What did you get?  Did the error
relate to anything I corrected above?  Unfortunately you won't get a
traceback for logic errors!  Also give the version of Python and your
operating system.  I am assuming you are using Python 3.



More information about the Tutor mailing list