Sobes.tech
Intern

# Potrebno je napísati funkciu f, ktorá odčíta druhý reťazec od prvého. # Odčítanie sa vykonáva iba vtedy, keď je druhý reťazec začiatkom prvého, # inak funkcia vráti prvý reťazec. # f('ahoj svet', 'ahoj') -> ' svet' # f('ahoj svet', 'hola') -> 'ahoj svet' # f('ahoj svet ahoj!', 'ahoj') -> ' svet ahoj!'

sobes.tech AI

Odpoveď od 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!'