dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
1.5 KiB
1.5 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 69738771fb5a7b8b24cca2a4 | Challenge 178: Truncate the Text | 29 | challenge-178 |
--description--
Given a string, return it as-is if it's 20 characters or shorter. If it's longer than 20 characters, truncate it to the first 17 characters and append "..." to the end of it (so it's 20 characters total) and return the result.
--hints--
truncate_text("Hello, world!") should return "Hello, world!".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(truncate_text("Hello, world!"), "Hello, world!")`)
}})
truncate_text("This string should get truncated.") should return "This string shoul...".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(truncate_text("This string should get truncated."), "This string shoul...")`)
}})
truncate_text("Exactly twenty chars") should return "Exactly twenty chars".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(truncate_text("Exactly twenty chars"), "Exactly twenty chars")`)
}})
truncate_text(".....................") should return "....................".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(truncate_text("....................."), "....................")`)
}})
--seed--
--seed-contents--
def truncate_text(text):
return text
--solutions--
def truncate_text(text):
if len(text) <= 20:
return text
return text[:17] + "..."