Skip to content

Instantly share code, notes, and snippets.

@roman-on
Created April 9, 2020 16:43
Show Gist options
  • Save roman-on/e1fb2ad5d769b93a94db9a51410713da to your computer and use it in GitHub Desktop.
Save roman-on/e1fb2ad5d769b93a94db9a51410713da to your computer and use it in GitHub Desktop.
"""
The function accepts three values representing ages: a, b, c and returns their sum.
Instructions
1. If the function is called without parameters, the default value of each age is 13.
2. If one of the values represents an age of adolescents between 13 and 19 (including them) but with the exception of ages 15 and 16 - fix its value using the function described below, so it is calculated as 0.
3. Write auxiliary function fix_age
1. The function accepts a number that represents age and returns it corrected according to the above rules. Call the fix_age function from the filter_teens function so that you do not repeat the age correction code three times.
Send
"""
# ~~~~~~~~~~~~~~~~~~ SUPOSE TO GET ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> filter_teens()
0
>>> filter_teens(1, 2, 3)
6
>>> filter_teens(2, 13, 1)
3
>>> filter_teens(2, 1, 15)
18
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def filter_teens(a = 13, b = 13, c = 13):
sum = fix_age(a) + fix_age(b) + fix_age(c)
print (sum)
def fix_age(age):
if age == 13 or age == 14 or age == 17 or age == 18 or age == 19:
return 0
else:
return age
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment