Hello again, I am working on another homework problem for my fundamentals class and my brain just isn't working. Like always I am looking for direction not for someone to do the work for me. So I have to create a program that asks for 5 test scores and will print out the grade (A, B, C, D, or F) for each score and then the average test score. The only instruction I have to follow is creating 2 functions (calc_average and determine_grade). I believe I have it where you can enter the 5 test scores and have the first function (calc_average) done. I am having an issue with how to determine the grade for each test score.

Here is what I have

``````def main():

test1 = int(input('What is the score of test number 1? ')
test2 = int(input('What is the score of test number 2? ')
test3 = int(input('What is the score of test number 3? ')
test4 = int(input('What is the score of test number 4? ')
test5 = int(input('What is the score of test number 5? ')

average = calc_average(first, second, third, forth, fifth)

print('The average score is ', average, '.', sep='')

def calc_average(first, second, third, forth, fifth):
average_grade = (first, second, third, forth, fifth)/5

def determine_grade(first, second, third, forth, fifth):

main()
``````

So I am not sure how to do the 2nd function (determine_grade). I was thinking a loop that will test each score for the grade condition (A being 90-100, B being 80-89, C being 70-79, D being 60-69 and F being anything below 60. If that is right I am not thinking correctly on how to get each test score to run through that process. In the chapter that we are in we learned about the Math module but not sure if that will be helpful in anyway.

Thanks again for any guidance.

Yes a for loop and using comparison operators will work.
Here is a hint.

``````t = (20, 58, 70, 92, 98)
A,F = 0,0

for mark in t:
if mark < 60:
F += 1
elif mark >= 90:
A += 1
else:
pass

print('{} people got A\n{} people got F'.format(A, F))
``````

Run this,here i use list comprehension,it can be written without and just append to a list.
Just to show that a loop can save you from writing test1,test2.....

``````score_lst = [int(input('What is the score of test number {}? '.format(i))) for i in range(1,6)]
print(score_lst)
``````

You should first test the calc_average function.
`print calc_average(75, 75, 75, 60, 90)`
Also you might want to convert to a float which depends on the version of Python you are using.

Thank you both very much. I am away from my computer at the moment but itching to get back and try this. I will update asap. +1 for Daniweb yet again :)

This line in main():
average = calc_average(first, second, third, forth, fifth)
should have the variable names given in main():
average = calc_average(test1, test2, test3, test4, test5)

The line in def calc_average(first, second, third, forth, fifth):
average_grade = (first, second, third, forth, fifth)/5
is wrong, you need to add all the scores and then divide by the number of scores.
Just note that '/' in Python2 is an integer division and may give wrong results.

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.