0

I was preforming some doctests in PyCharm and I ran the test in the python console. It passes one and fails the other, but the failure shows the value returned being the correct value. Does anyone know what I might be missing or if this is a known error in PyCharm, etc?

Here is the code

def friend_date(a, b):
    """
    Returns True if they have any hobbies in common, False is not.

    >>> elmo = ('Elmo', 5, ['hugging', 'being nice'])
    >>> sauron = ('Sauron', 5000, ['killing hobbits', 'chess'])
    >>> gandalf = ('Gandalf', 10000, ['waving wands', 'chess'])

    >>> friend_date(elmo, sauron)
    False

    >>> friend_date(sauron, gandalf)
    True 
    """
    return bool(set(a[2]) & set(b[2]))
2
  • 1
    Your True line has a trailing space. That matters. Commented Dec 10, 2020 at 7:51
  • Didn't realize spaces mattered like that in python, only thought it mattered to indent properly. Thank you so much @user2357112supportsMonica Commented Dec 10, 2020 at 8:51

1 Answer 1

1

Indeed as @user2357112 pointed out you have space in the expected output for your second test case. I tested with this code and it worked:

def friend_date(a, b):
    """
    Returns True if they have any hobbies in common, False is not.

    >>> elmo = ('Elmo', 5, ['hugging', 'being nice'])
    >>> sauron = ('Sauron', 5000, ['killing hobbits', 'chess'])
    >>> gandalf = ('Gandalf', 10000, ['waving wands', 'chess'])

    >>> friend_date(elmo, sauron)
    False

    >>> friend_date(sauron, gandalf)
    True
    """
    return bool(set(a[2]) & set(b[2]))
Sign up to request clarification or add additional context in comments.

1 Comment

@brent-franklin if it answers your question please mark it as resolved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.