Passed
Push — master ( e8c73d...5082ab )
by Ken M.
01:37
created

goes_right_after.goes_after()   A

Complexity

Conditions 2

Size

Total Lines 7
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nop 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
def goes_after(word: str, first: str, second: str) -> bool:
2
    try:
3
        first_index = word.index(first)
4
        second_index = word.index(second)
5
    except ValueError:
6
        return False
7
    return second_index == first_index + 1
8
9
10
if __name__ == "__main__":
11
    print("Example:")
12
    print(goes_after("world", "w", "o"))
13
14
    # These "asserts" are used for self-checking and not for an auto-testing
15
    assert goes_after("world", "w", "o") == True
16
    assert goes_after("world", "w", "r") == False
17
    assert goes_after("world", "l", "o") == False
18
    assert goes_after("panorama", "a", "n") == True
19
    assert goes_after("list", "l", "o") == False
20
    assert goes_after("", "l", "o") == False
21
    assert goes_after("list", "l", "l") == False
22
    assert goes_after("world", "d", "w") == False
23
    assert goes_after("transport", "r", "t") == False
24
    print("Coding complete? Click 'Check' to earn cool rewards!")
25