[Tutor] First program

Luke Paireepinart rabidpoobear at gmail.com
Sat Mar 13 03:33:35 CET 2010


On Fri, Mar 12, 2010 at 8:30 PM, Andre Engels <andreengels at gmail.com> wrote:

> On Sat, Mar 13, 2010 at 3:11 AM, Ray Parrish <crp at cmc.net> wrote:
> > Andre Engels wrote:
> >>
> >> On 3/12/10, yd <ydmt923 at gmail.com> wrote:
> >>>  else:
> >>>    raise Exception('{0}, is not a valid choice'.format(choice))
> >>>
> >>
> >> This will cause the program to stop-with-error if something wrong is
> >> entered. I think that's quite rude. I would change this to:
> >>  else:
> >>    print('{0}, is not a valid choice'.format(choice))
> >>
> >
> > Here's what I get from that, could you please explain why?
>
> You're probably using Python 2.4 or 2.5; the .format method has been
> introduced in Python 2.6, and is considered the 'standard' way of
> working in Python 3. For older Python versions, this should read
>
> print('%s, is not a valid choice'%(choice))
>
> Also you don't have to use parenthesis around single items, and also print
is not usually used as a function either.
So really for older versions the convention would be
print "%s, is not a valid choice" % choice

-Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100312/ad0ff3e5/attachment.html>


More information about the Tutor mailing list