-1

I have been trying to test the argument test scores to see if any tests are below 50. If so it should return fail. If the avg is above 70 and no tests are below 50 then it should return pass.

def course_grader(test_scores):

    avg_grade = sum(test_scores) / len(test_scores)

    if avg_grade >= 70 and test_scores >= 50:
        print("pass")

    elif avg_grade < 70 or test_scores < 50:
        print("fail")
        break



def main():
    print(course_grader([100,75,45]))     # "fail"
    print(course_grader([100,70,85]))     # "pass"
    print(course_grader([80,60,60]))      # "fail"
    print(course_grader([80,80,90,30,80]))  # "fail"
    print(course_grader([70,70,70,70,70]))  # "pass"

if __name__ == "__main__":
    main()

I also tried using a for loop but it was giving me too many answers.

SherylHohman
  • 16,580
  • 17
  • 88
  • 94
Sean
  • 1
  • 1
  • 1
    `any([x<50 for x in [30,60,70]])` will yield `True`. `any([x<50 for x in [60,60,70]])` will yield `False`. – Bill Bell Aug 05 '17 at 19:38

2 Answers2

1

You can check if the min(test_scores) >= 50. If minis higher or equal than 50, then there is no int in test_scores inferior to 50.

Also, there are three issues in your code.

First, you canot use break statement outside of a loop. This will raise a SyntaxError.

Second, your function doesn't return anything you can print. Your main() will output 'pass' or 'fail' and then None for each print. You should remove the print in main() or replace them in course_grader() by return.

Finally, your elif can be replaced by an else. If avg_grade >= 70 and test_scores >= 50 isn't True, then by necessity either (or both) avg_code is < 70 or test_score is < 50.

Unatiel
  • 1,060
  • 1
  • 11
  • 17
1

As pointed out by @Bill Bell, the use of any or all functions might be useful here:

def course_grader(test_scores):

    avg_grade = sum(test_scores) / len(test_scores)

    if avg_grade >= 70 and all([x >= 50 for x in test_scores]):
        print("pass")

    elif avg_grade < 70 or any([x < 50 for x in test_scores]):
        print("fail")
Rajan Chauhan
  • 1,378
  • 1
  • 13
  • 32
Some Guy
  • 1,787
  • 11
  • 15