This is the question i was given
---------------------------------------------------
Here is a program that prompts the user to enter a student’s marks, and then prints out whether they have passed or failed a unit.
'''calculate a students grade given their final mark'''

def calcFinal( asg1, asg2, exam ):
final = asg1 + asg2 + exam
return final

def main():
asg1Mark = int(raw_input("Enter Asg1 mark: "))
asg2Mark = int(raw_input("Enter Asg2 mark: "))
examMark = int(raw_input("Enter Exam mark: "))

finalMark = calcFinal(asg1Mark, asg2Mark, examMark)
print "Final mark is %d, grade is" % finalMark,
if finalMark < 50:
print "Fail"
else:
print "Pass"

main()
Modify the program so that it prints out the students grade, assuming standard university cutoffs for the different grades( ie < 50 FAIL, <65 PASS, < 75 CREDIT, < 85 DISTINCTION, and >= 85 HIGH DISTINCTION.
--------------------------------------------------------------------
and this is code ive been working on

'''calculate a students grade given their final mark''' 

def calcFinal( asg1, asg2, exam ): 
    final = asg1 + asg2 + exam
    return final 

def main(): 
    asg1Mark = int(raw_input("Enter Asg1 mark: ")) 
    asg2Mark = int(raw_input("Enter Asg2 mark: ")) 
    examMark = int(raw_input("Enter Exam mark: ")) 

    finalMark = calcFinal(asg1Mark, asg2Mark, examMark) 
    print "Final mark is %d, grade is" % finalMark,

    
    if finalMark < 50: 
        print "Fail"
    elif finalMark < 65:
        print "Pass"
    elif finalMark < 75:
        print "credit"
    elif finalMark < 85:
        print "Distinction"
    elif finalMark >= 85:
        print "High Distinction"
    elif finalMark < 100:
        print "High Distinction"
    else:
        print "Invaild selction"

main()

But its not getting the result i wanted :(
If anyone can point out my mistake or help me out'
please reply

So, what result to you want to get?

If the highest final grade cannot exceed 100, then rewrite your if statments like this ...

if finalMark < 50: 
        print "Fail"
    elif finalMark < 65:
        print "Pass"
    elif finalMark < 75:
        print "Credit"
    elif finalMark < 85:
        print "Distinction"
    elif finalMark <= 100:
        print "High Distinction"
    else:
        print "Invaild selection"

Somthing like this,i make a mark_check() function.
Use exception handling to catch wrong input.

Not much wrong with you code just test the if-elif-else condition to get the result you want.

def calcFinal():
    while True:
        try:
            asg1Mark = int(raw_input("Enter Asg1 mark: ")) 
            asg2Mark = int(raw_input("Enter Asg2 mark: ")) 
            examMark = int(raw_input("Enter Exam mark: ")) 
            final = asg1Mark + asg2Mark + examMark         
            return final
        except ValueError:
            print 'Only numbers,try again'

def mark_check(finalMark):
    print "Final mark is %d, grade is" % finalMark,  
    if finalMark < 50: 
        print "Fail"
    elif finalMark <= 65:
        print "Pass"
    elif finalMark <= 75:
        print "credit"
    elif finalMark <= 85:
        print "Distinction"
    elif finalMark >= 85:
        print "High Distinction"   
    else:
        print "Invaild selction"

def main():
    finalMark = calcFinal() 
    mark_check(finalMark)

if __name__ == "__main__":
    main()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.