[Tutor] stuck newbie [descriptive variable names]

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon, 19 Aug 2002 01:02:05 -0700 (PDT)


On Sun, 18 Aug 2002, paul meaney wrote:

> Im a total newbie and this is my first effort at writing my own bit of
> code.

Cool!  If you don't mind, I wanted to make some comments on the code.
Sean already caught the initialzation bug, so I'll assume that the code is
working fine now.


> while hw + hd + hl != 6 :
>     hw = input ("Enter number home teams no. of home wins out of last six games 6: ")
>     hd = input ("Enter number home teams no. of home draws out of last six games 6: ")
>     hl = input ("Enter number home teams no. of home defeats out of last six games 6: ")
[some code cut]

This block of code looks like it tries to read the following: wins, draws,
and losses, and tries to make sure that the numbers make sense.  Sounds
good so far.

If it's possible, you may want to name your variables more descriptively.
'hw' here stands for 'home wins', when it could easily also mean 'hot
water', or 'home world'.  *grin*


So something like:

###
    home_wins = input("Enter home teams no. of home wins: ")
    home_draws = input("Enter home teams no. of home draws: ")
    home_losses = input("Enter home teams no. of home losses: ")
###

which is a little longer to type, admittedly, but is a little easier to
read as well.


Best of wishes to you!