At 06:04 PM 10/12/2005, [EMAIL PROTECTED] wrote:
>hello
>
>below is my code and everytime I input a value of 16 or more it keeps
>returning sophomore. could anyone help me figure out what to change so
>that it won't return sophmore for things greater than or equal to 16?
>
>def getcredits(num):
>     if num < 7:
>         return 'Freshman'
>     elif num >= 7:
>         return 'Sophomore'
>     elif num <16:
>         return 'Sophomore'
>     elif num >= 16:
>         return 'Junior'
>     elif num < 26:
>         return 'Junior'
>     else:
>         return 'Senior'

I have a preference for separating data and control structure. So I would:

def getcredits(num):
     rank = ((7, 'Freshman'), (16, 'Sophomore'), (26, 'Junior'), (999, 
'Senior')
     for limit, class in rank:
         if num < limit:
             return class

>def main():
>     g = input('Enter number of credits:')
>     print 'Your standing is %s' % (getcredits(int(g)))
>
>main()
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to