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
85 lines
1.9 KiB
Markdown
85 lines
1.9 KiB
Markdown
---
|
|
id: 698a1a73ade5ac0e19180fa7
|
|
title: "Challenge 204: Sum the Letters"
|
|
challengeType: 29
|
|
dashedName: challenge-204
|
|
---
|
|
|
|
# --description--
|
|
|
|
Given a string, return the sum of its letters.
|
|
|
|
- Letters are A-Z in uppercase or lowercase
|
|
- Letter values are: `"A"` = 1, `"B"` = 2, ..., `"Z"` = 26
|
|
- Uppercase and lowercase letters have the same value.
|
|
- Ignore all non-letter characters.
|
|
|
|
# --hints--
|
|
|
|
`sum_letters("Hello")` should return `52`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(sum_letters("Hello"), 52)`)
|
|
}})
|
|
```
|
|
|
|
`sum_letters("freeCodeCamp")` should return `94`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(sum_letters("freeCodeCamp"), 94)`)
|
|
}})
|
|
```
|
|
|
|
`sum_letters("The quick brown fox jumps over the lazy dog.")` should return `473`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(sum_letters("The quick brown fox jumps over the lazy dog."), 473)`)
|
|
}})
|
|
```
|
|
|
|
`sum_letters("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ex nisl, pretium eu varius blandit, facilisis quis eros. Vestibulum ante ipsum primis in faucibus orci.")` should return `1681`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(sum_letters("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ex nisl, pretium eu varius blandit, facilisis quis eros. Vestibulum ante ipsum primis in faucibus orci."), 1681)`)
|
|
}})
|
|
```
|
|
|
|
`sum_letters("</404>")` should return `0`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(sum_letters("</404>"), 0)`)
|
|
}})
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```py
|
|
def sum_letters(s):
|
|
|
|
return s
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```py
|
|
def sum_letters(s):
|
|
total = 0
|
|
for char in s:
|
|
upper = char.upper()
|
|
if 'A' <= upper <= 'Z':
|
|
total += ord(upper) - ord('A') + 1
|
|
return total
|
|
```
|