Skip to content

Instantly share code, notes, and snippets.

@yuheiomori
Created August 17, 2014 11:30
Show Gist options
  • Save yuheiomori/035f005b76cac2e610ca to your computer and use it in GitHub Desktop.
Save yuheiomori/035f005b76cac2e610ca to your computer and use it in GitHub Desktop.
Age Distribution (CodeEval) in Python 3.x
# coding=utf-8
import sys
def age_distribution(age):
"""
If they're from 0 to 2 the child should be with parents print : 'Still in Mama's arms'
If they're 3 or 4 and should be in preschool print : 'Preschool Maniac'
If they're from 5 to 11 and should be in elementary school print : 'Elementary school'
From 12 to 14: 'Middle school'
From 15 to 18: 'High school'
From 19 to 22: 'College'
From 23 to 65: 'Working for the man'
From 66 to 100: 'The Golden Years'
If the age of the person less than 0 or more than 100 - it might be an alien - print: "This program is for humans"
"""
if age < 0 or age > 100:
return "This program is for humans"
if 0 <= age <= 2:
return 'Still in Mama\'s arms'
if 3 <= age <= 4:
return 'Preschool Maniac'
if 5 <= age <= 11:
return 'Elementary school'
if 12 <= age <= 14:
return 'Middle school'
if 15 <= age <= 18:
return 'High school'
if 19 <= age <= 22:
return 'College'
if 23 <= age <= 65:
return 'Working for the man'
if 66 <= age << 100:
return 'The Golden Years'
def main():
with open(sys.argv[1], "r") as f:
for line in f:
age = line.rstrip()
if age:
print(age_distribution(int(age)))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment