Sobes.tech
Intern

# Ir nepieciešams uzrakstīt funkciju f, kas atņem otro rindu no pirmās. # Atņemšana notiek tikai tad, ja otra rinda ir pirmās sākums, # pretējā gadījumā funkcija atgriež pirmo rindu. # f('sveiks pasaule', 'sveiks') -> ' pasaule' # f('sveiks pasaule', 'hola') -> 'sveiks pasaule' # f('sveiks pasaule sveiks!', 'sveiks') -> ' pasaule sveiks!'

sobes.tech AI

Atbilde no AI

python def f(s1: str, s2: str) -> str: if s1.startswith(s2): return s1[len(s2):] return s1

Примеры:

print(f('hello world', 'hello')) # ' world' print(f('hello world', 'hola')) # 'hello world' print(f('hello world hello!', 'hello')) # ' world hello!'