Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

101 lines
2.2 KiB
Markdown

---
id: 698a1a73ade5ac0e19180fa9
title: "Challenge 206: Playing Card Values"
challengeType: 29
dashedName: challenge-206
---
# --description--
Given an array of playing cards, return a new array with the numeric value of each card.
Card Values:
- An Ace (`"A"`) has a value of 1.
- Numbered cards (`"2"` - `"10"`) have their face value: 2 - 10, respectively.
- Face cards: Jack (`"J"`), Queen (`"Q"`), and King (`"K"`) are each worth 10.
Suits:
- Each card has a suit: Spades (`"S"`), Clubs (`"C"`), Diamonds (`"D"`), or Hearts (`"H"`).
Card Format:
- Each card is represented as a string: `"valueSuit"`. For Example: `"AS"` is the Ace of Spades, `"10H"` is the Ten of Hearts, and `"QC"` is the Queen of Clubs.
# --hints--
`card_values(["3H", "4D", "5S"])` should return `[3, 4, 5]`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(card_values(["3H", "4D", "5S"]), [3, 4, 5])`)
}})
```
`card_values(["AS", "10S", "10H", "6D", "7D"])` should return `[1, 10, 10, 6, 7]`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(card_values(["AS", "10S", "10H", "6D", "7D"]), [1, 10, 10, 6, 7])`)
}})
```
`card_values(["8D", "QS", "2H", "JC", "9C"])` should return `[8, 10, 2, 10, 9]`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(card_values(["8D", "QS", "2H", "JC", "9C"]), [8, 10, 2, 10, 9])`)
}})
```
`card_values(["AS", "KS"])` should return `[1, 10]`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(card_values(["AS", "KS"]), [1, 10])`)
}})
```
`card_values(["10H", "JH", "QH", "KH", "AH"])` should return `[10, 10, 10, 10, 1]`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(card_values(["10H", "JH", "QH", "KH", "AH"]), [10, 10, 10, 10, 1])`)
}})
```
# --seed--
## --seed-contents--
```py
def card_values(cards):
return cards
```
# --solutions--
```py
def card_values(cards):
values = []
for card in cards:
value_str = card[:-1]
if value_str == "A":
value = 1
elif value_str in ["J", "Q", "K"]:
value = 10
else:
value = int(value_str)
values.append(value)
return values
```