ten small Python programs

BartlebyScrivener bscrivener42 at gmail.com
Sun May 27 08:45:44 EDT 2007


On May 26, 1:43 pm, Steve Howell <showel... at yahoo.com> wrote:

>     ------
>     parentRabbits, babyRabbits = (1, 1)
>     while babyRabbits < 100:
>         print 'This generation has %d rabbits' %
> babyRabbits
>         parentRabbits, babyRabbits = (babyRabbits,
> parentRabbits + babyRabbits)
>
>     ------
>     # def defines a method in Python
>     def tax(itemCharge, taxRate = 0.05):
>         return itemCharge * taxRate
>     print '%.2f' % tax(11.35)
>     print '%.2f' % tax(40.00, 0.08)
>

For the person new to programming (doesn't come from C or other
languages), I think you need to add a separate explanation of string
formatting and how it works, or at least add a comment that tells them
you are using string formatting so that they can search and find out
how it works. If your aim is to teach simple programming concepts, why
confuse them so early on with fancy interpolation?

Something like

# uses Python string formatting
# http://docs.python.org/lib/typesseq-strings.html

but really I think it will just be a distraction

rd





More information about the Python-list mailing list