[Tutor] return values function

Lea Parker lea-parker at bigpond.com
Fri Apr 22 08:59:18 CEST 2011



I am hoping someone can put me on the right track. The code below includes
the assignment question at the beginning.


I seem to have been able to calculate average ok, but what I can't seem to
do is sort it so it will return a grade for each result.


Can you give me some advice to head me in the right direction please. My
code is:


"""Write a program that asks the user to enter 5 sets tests scores. The

should then display the 'letter grade' (A, B, C, D, F) for each test score,

the overall average test schore. Write the following functions in the

* Calc_average: This function should take five test scores as parameters,

return the average score.

*determine_grade; this function should take a single test score as a

and return a letter grade for the test. The letter grade should be on the

following grade scale: 90-100: A, 80-89: B, 70-79: C, 60-69: D, <60: F.""" 



def main():


    #Get users first test result

    test1 = int(raw_input('Enter the score for test 1: '))


    #Get users second test result

    test2 = int(raw_input('Enter the score for test 2: '))


    #Get users third test result

    test3 = int(raw_input('Enter the score for test 3: '))


    #Get users forth test result

    test4 = int(raw_input('Enter the score for test 4: '))


    #Get users fifth test result

    test5 = int(raw_input('Enter the score for test 5: '))


    #Get the sum of the test results

    cal_average = sum(test1, test2, test3, test4, test5)/5


    #Display the total of tests

    print 'Together your tests average is: ', cal_average

    print 'Your grade is: ', grade


    # The sum function to total all tests

def sum(test1, test2, test3, test4, test5):

    result = test1 + test2 + test3 + test4 + test5

    return result



def determine_grade(score):

    #Determine the grade for each score

    if score <101 and score >89:

        score = A

    elif score <90 and score >79:

        score = B

    elif score <80 and score >69:

        score = C

    elif score <70 and score >59:

        score = D


        score = F

    return score




# Call the main function


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110422/fede14a5/attachment.html>

More information about the Tutor mailing list