1 Task

Write a file with one function: creepy. creepy should have two arguments, the ages of two people. It should return False if the two may date each other without being creepy, True. See dating.py for a definition of creepy.

Return the Boolean values1 True and False, not the strings "True" and "False".

Note: it is possible to solve this problem using if, but that is not encouraged. Your function should neither print nor ask for any input. You should not have any code outside of the function.

You may assume that we only invoke the function with the younger age ≥ 14 and the older age in the second position.

2 Example Invocations

When you run maydate.py, nothing should happen. It defines a function, it does not run it.

If in another file (which you do not submit) you write the following:

import maydate

print(maydate.creepy(18, 80))
print(maydate.creepy(50, 80))
print(type(maydate.creepy(50, 80)))

you should get the following output:

<class 'bool'>

3 Thought Question

We won’t test it, but what does your code do if you pass in the older age first?

print(maydate.creepy(22, 18))
print(maydate.creepy(31, 18))

How hard would it be to make it work for both age orders?

We won’t test fractional ages, but does your code work for them? For example, does it think that a fifteen-year-old can date a fourteen-and-a-half year old?

The rule as given says it is creepy for a 13-year-old to date anyone. How hard would it be to make a different function that is more permissive, always allowing people to date ±1 year even if they are under 16? (Don’t use a revised rule like this for the function you turn in!)

4 Troubleshooting

You should probably write two python files for this assignment; the one you turn in (maydate.py) that defines creepy and a separate file you use to test it. In your testing file,

  • Don’t forget to import maydate
  • Try both the examples we give above and other examples of your own
  • When adding examples, make sure you know what the right answer is supposed to be!

Confused on how to not use if? Consider the following example:

def example(x, y):
    '''returns True if x is bigger than y, False if it is not'''
    return x > y

Remember that Python cares about indentation, and that every more-indented block must be preceded by a colon :.

Want to write something more than just <? and >? There is a chart of other comparison operators (the Python equivalents of things like ≠ and ≤ in Python) in §6.1.2.

  1. Not every section discussed Boolean values. Comparisons (like x < 3) evalaute to Boolean values, called bool by Python. See the Troubleshooting section, a summary of types, or section 6.1 of the textbook for more↩︎