Advertisement
Lyuben_Andreev

lowerUpper

Jun 14th, 2024
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. # Входен низ и търсена дума
  2. my_string = "Hello GoSho, welcome to the Gosho world. This GOSHO is amazing."
  3. search_word = "gosho"
  4.  
  5. # Преобразуване на низа и думата в малки букви
  6. my_string_lower = my_string.lower()
  7. search_word_lower = search_word.lower()
  8.  
  9. # Проверка дали думата присъства в низа
  10. if search_word_lower in my_string_lower:
  11.     print(f"The word '{search_word}' is present in the string.")
  12. else:
  13.     print(f"The word '{search_word}' is not present in the string.")
  14.  
  15. # Броене на срещанията на думата в низа
  16. count = my_string_lower.count(search_word_lower)
  17. print(f"The word '{search_word}' appears {count} times in the string.")
  18.  
  19. # Намиране на всички позиции на срещанията на думата в низа
  20. positions = []
  21. index = 0
  22. while index < len(my_string_lower):
  23.     index = my_string_lower.find(search_word_lower, index)
  24.     if index == -1:
  25.         break
  26.     positions.append(index)
  27.     index += len(search_word_lower)
  28.  
  29. print(f"The word '{search_word}' appears at positions: {positions}")
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement