[Tutor] help with elif statements

Hans Dushanthakumar Hans.Dushanthakumar at navman.com
Thu Oct 13 03:27:29 CEST 2005


U might wanna change the code to something along the lines of

 def getcredits(num):
    if num < 7:
        return 'Freshman'
    elif num >= 7 and num <16
        return 'Sophomore'
    elif num >= 16 and num < 26:
        return 'Junior'

Etc...

Or even 

 def getcredits(num):
    if num < 7:
        return 'Freshman'
    elif num <16
        return 'Sophomore'
    elif num < 26:
        return 'Junior' 
...



-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On
Behalf Of andrade1 at umbc.edu
Sent: Thursday, 13 October 2005 2:05 p.m.
To: tutor at python.org
Subject: [Tutor] help with elif statements

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'

def main():
    g = input('Enter number of credits:')
    print 'Your standing is %s' % (getcredits(int(g)))

main()

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


More information about the Tutor mailing list