Re: [Tutor] Using Python to solve factoria

2016-12-22 Thread Alan Gauld via Tutor
On 21/12/16 07:50, Hedgar wrote:

> I really happy to be accepted to the list!

You're welcome, but one very important thing to
note is that you should always post to this list
in plain text, not HTML. That's because HTML loses
the formatting of the code (see below) and in
Python formatting is very important.

> def factoria(numb):
> While numb > 1:
> If numb==0:
> return 1
> Else:
> result = numb*(numb-1)
> numb = numb -1
> return result
> factoria(5)

As you see we lost formatting, however this code
would never run because it is not valid Python.
Python is case sensitive so you need to use
'while' not 'While' etc.

> #should output 120
> What am I not getting right?

Another important point when postring is to
always include any error messages(in full)
that you get. They contain vital clues as
to what is wrong.

I see Bob Stepp has replied re the actual code,
so I assume his mail reader managed to interpret
it correctly - or maybe he just guessed. But
following the above guidelines will help you
get good answers more quickly in future.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using Python to solve factoria

2016-12-21 Thread boB Stepp
Welcome!

On Wed, Dec 21, 2016 at 1:50 AM, Hedgar  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
else:
result = numb*(numb-1)
numb = numb -1

return result

print(factoria(5))

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
exits.

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.

HTH!

boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Using Python to solve factoria

2016-12-21 Thread Hedgar
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?
Thanks
Heddy


Sent from my iPhone

> On 21 Dec 2016, at 01:17, tutor-requ...@python.org wrote:
> 
> Welcome to the Tutor@python.org mailing list! This list is for folks
> who want to ask (and/or answer) questions from folks who wish to learn
> how to program with Python.  Feel free to ask even the most basic of
> questions -- that's what the list is for!
> 
> For best results when asking a question on this list: - Try to write
> some code to solve your problem - Show the code you have written -
> Describe what the code does and what you want it to do - If the code
> generates an error, copy and paste the entire error message, including
> the traceback, into your email. - Tell us what OS and Python version
> you are using.
> 
> - Don't ask us to do your homework. - Don't assume we know what you
> are talking about. If you are having trouble with a third-party
> library, include a link to the library home page.
> 
> When replying to a posting: - Use Reply All to reply to the entire
> list - Don't top post - put your reply after the text to which you are
> replying
> 
> For all posts: - Format your email as plain text, not HTML
> 
> 
> To post to this list, send your message to:
> 
>  tutor@python.org
> 
> General information about the mailing list is at:
> 
>  https://mail.python.org/mailman/listinfo/tutor
> 
> If you ever want to unsubscribe or change your options (eg, switch to
> or from digest mode, change your password, etc.), visit your
> subscription page at:
> 
>  
> https://mail.python.org/mailman/options/tutor/ajakzhedgar%2Bnewsletter%40gmail.com
> 
> 
> You can also make such adjustments via email by sending a message to:
> 
>  tutor-requ...@python.org
> 
> with the word `help' in the subject or body (don't include the
> quotes), and you will get back a message with instructions.
> 
> You must know your password to change your options (including changing
> the password, itself) or to unsubscribe without confirmation.  It is:
> 
>  analyst
> 
> Normally, Mailman will remind you of your python.org mailing list
> passwords once every month, although you can disable this if you
> prefer.  This reminder will also include instructions on how to
> unsubscribe or change your account options.  There is also a button on
> your options page that will email your current password to you.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor