fork download
  1. def determine_pass_fail(scores):
  2. # Define the minimum score required to pass each subject
  3. min_subject_score = 40
  4. # Define the minimum average score required to pass overall
  5. min_average_score = 50
  6.  
  7. # Check if the student has failed in any subject
  8. for subject, score in scores.items():
  9. if score < min_subject_score:
  10. print(f"Student fails because the score in {subject} is below {min_subject_score}.")
  11. return "Fail"
  12.  
  13. # Calculate the average score
  14. average_score = sum(scores.values()) / len(scores)
  15.  
  16. # Check if the average score is below the required minimum
  17. if average_score < min_average_score:
  18. print(f"Student fails because the average score {average_score:.2f} is below {min_average_score}.")
  19. return "Fail"
  20.  
  21. # If all conditions are met, the student passes
  22. print(f"Student passes with an average score of {average_score:.2f}.")
  23. return "Pass"
  24.  
  25. # Example usage
  26. student_scores = {
  27. "Math": 45,
  28. "English": 55,
  29. "Science": 60,
  30. "History": 35 # This will cause the student to fail
  31. }
  32.  
  33. result = determine_pass_fail(student_scores)
  34. print(f"Result: {result}")
Success #stdin #stdout 0.03s 9612KB
stdin
Standard input is empty
stdout
Student fails because the score in History is below 40.
Result: Fail