Подсчитать число предложений в файле( предложения заканчиваются на знаки: «.», «!», «?» и т.д) — Python(Питон)

def count_sentences(text):
    sentence_delimiters = ['.', '!', '?']
    count = 0
    for char in text:
        if char in sentence_delimiters:
            count += 1
    return count

# Example usage
text = "This is a sample text. It has multiple sentences! How many sentences does it have?"
sentence_count = count_sentences(text)
print("Number of sentences:", sentence_count)

Leave a Comment