Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Cut Sentence solution in Clear category for Cut Sentence by faccanoni
def cut_sentence(line: str, length: int) -> str:
L = line.split()
sol = ""
for ell in L:
if len(sol)+len(ell)<=length:
sol += ell+' '
else:
sol = sol[:-1]+'...'
return sol
return sol[:-1]
assert cut_sentence("Hi my name is Alex", 8) == "Hi my..."
assert cut_sentence("Hi my name is Alex", 4) == "Hi..."
assert cut_sentence("Hi my name is Alex", 20) == "Hi my name is Alex"
assert cut_sentence("Hi my name is Alex", 18) == "Hi my name is Alex"
print("The mission is done! Click 'Check Solution' to earn rewards!")
Oct. 31, 2022
Comments: