def determine_pass_fail(scores):
# Define the minimum score required to pass each subject
min_subject_score = 40
# Define the minimum average score required to pass overall
min_average_score = 50
# Check if the student has failed in any subject
for subject, score in scores.items():
if score < min_subject_score:
print(f"Student fails because the score in {subject} is below {min_subject_score}.")
return "Fail"
# Calculate the average score
average_score = sum(scores.values()) / len(scores)
# Check if the average score is below the required minimum
if average_score < min_average_score:
print(f"Student fails because the average score {average_score:.2f} is below {min_average_score}.")
return "Fail"
# If all conditions are met, the student passes
print(f"Student passes with an average score of {average_score:.2f}.")
return "Pass"
# Example usage
student_scores = {
"Math": 45,
"English": 55,
"Science": 60,
"History": 35 # This will cause the student to fail
}
result = determine_pass_fail(student_scores)
print(f"Result: {result}")
ZGVmIGRldGVybWluZV9wYXNzX2ZhaWwoc2NvcmVzKToKICAgICMgRGVmaW5lIHRoZSBtaW5pbXVtIHNjb3JlIHJlcXVpcmVkIHRvIHBhc3MgZWFjaCBzdWJqZWN0CiAgICBtaW5fc3ViamVjdF9zY29yZSA9IDQwCiAgICAjIERlZmluZSB0aGUgbWluaW11bSBhdmVyYWdlIHNjb3JlIHJlcXVpcmVkIHRvIHBhc3Mgb3ZlcmFsbAogICAgbWluX2F2ZXJhZ2Vfc2NvcmUgPSA1MAoKICAgICMgQ2hlY2sgaWYgdGhlIHN0dWRlbnQgaGFzIGZhaWxlZCBpbiBhbnkgc3ViamVjdAogICAgZm9yIHN1YmplY3QsIHNjb3JlIGluIHNjb3Jlcy5pdGVtcygpOgogICAgICAgIGlmIHNjb3JlIDwgbWluX3N1YmplY3Rfc2NvcmU6CiAgICAgICAgICAgIHByaW50KGYiU3R1ZGVudCBmYWlscyBiZWNhdXNlIHRoZSBzY29yZSBpbiB7c3ViamVjdH0gaXMgYmVsb3cge21pbl9zdWJqZWN0X3Njb3JlfS4iKQogICAgICAgICAgICByZXR1cm4gIkZhaWwiCgogICAgIyBDYWxjdWxhdGUgdGhlIGF2ZXJhZ2Ugc2NvcmUKICAgIGF2ZXJhZ2Vfc2Nvc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