Skip to content

Instantly share code, notes, and snippets.

@md2perpe
Created January 30, 2022 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save md2perpe/8d34410465d5e059ee3528d81b5150ad to your computer and use it in GitHub Desktop.
Save md2perpe/8d34410465d5e059ee3528d81b5150ad to your computer and use it in GitHub Desktop.
' ** PYTHON CODE CHALLENGE - SCHOOL ADMISSIONS ** '
# write code to handle admissions for a school - print results
# rules: pass test and interview. If applicant is legacy
# passing either test or interview is enough to be admitted
# your output should be sorted
# output = 'Accepted students: An, Bo, Mo, My, Xi'
appl =['Jay','Sam','Vi','Li','My','Xi','On','Mo','An','Bo']
test_ok =['xi','my','sam','an','mo','on']
int_ok =['my','li','an','mo','bo','jay']
legacy = ['sue','bo','xi']
def accepted(person):
key = person.lower()
passed_test = key in test_ok
passed_int = key in int_ok
if key in legacy:
return passed_test or passed_int
else:
return passed_test and passed_int
accepted_students = sorted(person for person in appl if accepted(person))
output = f"Accepted students: {', '.join(accepted_students)}"
print(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment