info_outline

Solutions will be available when this assignment is resolved, or after a few failing attempts.

All in String

The function all_in_string receives a phrase and 3 words, and it should count how many of those words appear in the original phrase at least once.

Example, given the sentence from our previous assignment:

Courage is not the absence of fear, but rather the judgement that something else is more important than fear
(Ambrose Redmoon)

How many of the following words you see included in that sentence: fear, judgement, Python? The answer is 2, because only fear and judgement are part of the original sentence.

Examples of all_in_string:

phrase = "Python is good. Python is Wise. I like Python"

all_in_string(phrase, 'Python', 'good', 'Ruby')  # 2
all_in_string(phrase, 'Python', 'Javascript', 'Ruby')  # 1
all_in_string(phrase, 'Python', 'Wise', 'good')  # 3
all_in_string(phrase, 'Ruby', 'Javascript', 'Perl')  # 0

Hint: The in operator might be handy.

Test Cases

test two in string - Run Test

def test_two_in_string():
    assert all_in_string('abcd', 'a', 'b', 'X') == 2
    assert all_in_string('abcd', 'a', 'X', 'b') == 2
    assert all_in_string('abcd', 'X', 'a', 'b') == 2

test only one in string - Run Test

def test_only_one_in_string():
    assert all_in_string('abcd', 'a', 'X', 'Y') == 1
    assert all_in_string('abcd', 'X', 'a', 'Y') == 1
    assert all_in_string('abcd', 'Y', 'X', 'a') == 1

test three in string - Run Test

def test_three_in_string():
    assert all_in_string('abcd', 'a', 'b', 'c') == 3
def all_in_string(a_string, s1, s2, s3): pass