string = input("Введите строку: ")
word_to_find = input("Введите слово для поиска: ")
count = 0
word = ""
found = False
for char in string:
if char == " ":
if word == word_to_find:
count += 1
found = True
else:
word += char
if found:
print("Количество вхождений слова:", count)
print("Слово не найдено в строке.")
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
string = input("Введите строку: ")
word_to_find = input("Введите слово для поиска: ")
count = 0
word = ""
found = False
for char in string:
if char == " ":
if word == word_to_find:
count += 1
found = True
word = ""
else:
word += char
if word == word_to_find:
count += 1
found = True
if found:
print("Количество вхождений слова:", count)
else:
print("Слово не найдено в строке.")