def double_O(s): result = '' for char in s: if char == 'o' or char == 'O': result += char * 2 else: result += char return result # Пример использования s = "Hello, World!" doubled_s = double_O(s) print(doubled_s) # Вывод: Helloo, Woorlld!
Задача 2:
def insert_dash(s): result = '' for char in s: result += char + '-' return result[:-1] # Пример использования s = "Hello" dashed_s = insert_dash(s) print(dashed_s) # Вывод: H-e-l-l-o
Решение:
Задача 1:
def double_O(s):result = ''
for char in s:
if char == 'o' or char == 'O':
result += char * 2
else:
result += char
return result
# Пример использования
s = "Hello, World!"
doubled_s = double_O(s)
print(doubled_s) # Вывод: Helloo, Woorlld!
Задача 2:
def insert_dash(s):result = ''
for char in s:
result += char + '-'
return result[:-1]
# Пример использования
s = "Hello"
dashed_s = insert_dash(s)
print(dashed_s) # Вывод: H-e-l-l-o