Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Created December 28, 2020 23:53
Show Gist options
  • Save ZechCodes/138b69e1eeb710e9eb9675d5b84c0c6f to your computer and use it in GitHub Desktop.
Save ZechCodes/138b69e1eeb710e9eb9675d5b84c0c6f to your computer and use it in GitHub Desktop.
Challenge 153 - Father and Son Ages

Challenge 153 - Father and Son Ages

Create a function that takes two arguments: a father's current age and his son's current age. Сalculate how many years ago the father was twice as old as his son, or in how many years he will be twice as old.

Examples

age_difference(36, 7) ➞ 22
# 22 years from now, the father will be 58 years old and his son will be 29 years old.

age_difference(55, 30) ➞ 5
# 5 years ago, the father was 50 years old and his son was 25 years old.

age_difference(42, 21) ➞ 0
import unittest
def find_twice_age(fathers_age: int, sons_age: int) -> int:
return 0 # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertEqual(find_twice_age(36, 7), 22)
def test_2(self):
self.assertEqual(find_twice_age(55, 30), 5)
def test_3(self):
self.assertEqual(find_twice_age(42, 21), 0)
def test_4(self):
self.assertEqual(find_twice_age(22, 1), 20)
def test_5(self):
self.assertEqual(find_twice_age(29, 0), 29)
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment