Click here to Skip to main content
15,896,478 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Write a course_grader function that takes a list of test scores as its parameter. It will add up these test scores and calculate an average score. It should then return a message of "pass" or "fail" depending on these two conditions:
If the average score is greater than or equal to 70 and no single test score is below 50, then return a message of "pass".
If the average score is lower than 70 or at least one test score is below 50, then return a message of "fail".
Some sample function calls with comments on what should be printed out are included in main for testing purposes. You should only put the code for the course_grader function into Vocareum.

RunSaveLoadShow CodeLens


1
def course_grader(test_scores):
2
# Your code here
3

4
def main():
5
print(course_grader([100,75,45])) # "fail"
6
print(course_grader([100,70,85])) # "pass"
7
print(course_grader([80,60,60])) # "fail"
8
print(course_grader([80,80,90,30,80])) # "fail"
9
print(course_grader([70,70,70,70,70])) # "pass"
10

11
if __name__ == "__main__":
12
main()
13


What I have tried:

I have tried all lots of if else statements and many other operations.
Posted
Updated 2-Aug-18 22:19pm

Take each statement in isolation and write down the steps necessary to get the result. Once you have all steps then start converting what you have written into code.

For example "It will add up these test scores and calculate an average score."
What is necessary for this part? Start with two variables, one that will hold the sum, and one the count: set both to zero. Add each value to the sum while counting the number of values. Once all values have been accumulated use the sum and the count to calculate the average.
 
Share this answer
 
Quote:
I have tried all lots of if else statements and many other operations.

So, you show no attempt to solve the problem yourself, you just say that you tried things, you have no question, you just want us to do your HomeWork.
HomeWork problems are simplified versions of the kind of problems you will have to solve in real life, their purpose is learning and practicing.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900