Write a function to count the occurances of a given character in a string.
user
def count_char(string, char):
    count = 0
    for c in string:
        if c == char:
            count += 1
    return count

print(count_char("hello world", "l"))

Output: 3
assistant