Solution 1

def char_in_string(a_string, char_to_look_for):
    count = 0
    while count < len(a_string):
        if char_to_look_for == a_string[count]:
            return True
        count += 1
    return False

Solution 2

def char_in_string(a_string, char_to_look_for):
    for char in a_string:
        if char_to_look_for == char:
            return True
            
    return False

Is Char in String

Use a for loops to complete the function char_in_string to check if char_to_look_for is in a_string.

Do NOT use the in keyword to determine if it is in there.

Return True if it is there and False if it is not.

Examples:

>>>  char_in_string("abcdef", "X")
False

>>>  char_in_string("abcXdef", "X")
True

Note: If you find the character, you can leave the loop early by using a break or a return statement.

Test Cases

test char not in string - Run Test

def test_char_not_in_string():
    assert char_in_string("abcdef", "X") == False

test char in string - Run Test

def test_char_in_string():
    assert char_in_string("abcXdef", "X") == True
def char_in_string(a_string, char_to_look_for): pass