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.9 KiB
1.9 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 698a1a73ade5ac0e19180fa7 | Challenge 204: Sum the Letters | 29 | 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.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sum_letters("Hello"), 52)`)
}})
sum_letters("freeCodeCamp") should return 94.
({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.
({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.
({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.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sum_letters("</404>"), 0)`)
}})
--seed--
--seed-contents--
def sum_letters(s):
return s
--solutions--
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