[Tutor] Class Tips

W W srilyk at gmail.com
Sun May 31 04:07:33 CEST 2009


On Sat, May 30, 2009 at 8:20 PM, David <david at abbottdavid.com> wrote:
>
> Alan Gauld wrote:
>>
>> "David" <david at abbottdavid.com> wrote
>>
>>> I took this program that determines a fertilizer application rate;
>>> ...
>>> And converted it to class/object to learn how they work. Just looking
for some pointers, if I did it correctly etc.
>>>
>>> <snip>

One thing that's probably not in the scope of the program but really usually
a good idea is error checking.
i.e.  this line:
rate = float(raw_input("Enter rate i.e. (0.5) : "))

could be converted to something like:
try:
    rate = float(raw_input("Enter rate..."))
except ValueError:
    print "Invalid input"
    #Quit or loop until valid input is entered.

HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090530/9a0a4e87/attachment.htm>


More information about the Tutor mailing list