Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconstituted V3 Repo PR2949 (https://github.com/exercism/v3/pull/2949) #2420

Merged
merged 3 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
235 changes: 54 additions & 181 deletions config.json

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions exercises/concept/black-jack/.docs/hints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# General

- [The Python Comparisons Tutorial][the python comparisons tutorial] and [Python comparisons examples][python comparisons examples] can be a great introduction.

## 1. Calculate the number of card

- You can use the [equality comparison operator][equality comparison operator] to get the number of the card.

## 2. Calculate the number of Ace

- You can use the [order comparisons operator][order comparisons operator]to decide the value of ace without the sum of hand exceeding 21.

## 3. Judge Blackjack

- You can use the [membership test operations][membership test operations] in `if` or `elif` syntax to find black-jack from the first two cards in your hand.

[the python comparisons tutorial]: https://docs.python.org/3/reference/expressions.html#comparisons
[python comparisons examples]: https://www.tutorialspoint.com/python/comparison_operators_example.htm
[equality comparison operator]: https://docs.python.org/3/reference/expressions.html#comparisons
[order comparisons operator]: https://docs.python.org/3/reference/expressions.html#comparisons
[membership test operations]: https://docs.python.org/3/reference/expressions.html#comparisons
50 changes: 50 additions & 0 deletions exercises/concept/black-jack/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
In this exercise, you're going to implement some rules from [Blackjack][blackjack]

You have some rules to implement for judging the result of the game.

**Note** : In this exercise, _A_ means an ace, _J_ means jack, _Q_ means queen, and _K_ means king card.

## 1. Calculate the number of card

Create the `number_of_card()` function with a parameter `card`. The value of _J, Q_ or _K_ is 10. If the `card` is _A_, then just return "ace".

```python
>>> number_of_card('K')
10
>>> number_of_card('A')
ace
```

## 2. Calculate the number of Ace

Create the `number_of_ace()` function with a parameter `hand`.

1. `hand` : the sum of cards in hand with an ace.

Ace is 1 or 11. You have to decide the value of ace without the sum of hand exceeding 21.

```python
>>> number_of_ace(19)
1
>>> number_of_ace(7)
11
```

## 3. Judge Blackjack

Create the `blackjack()` function with a parameter `hand`.

1. `hand` : first two cards in hand.

This function should return if the hand is blackjack. There's must be an ace card in `hand`.

**Note** : If the player has an Ace and a ten-value card, it is called a _Blackjack_. Ten-value cards include _10, J, Q, K_. I think you may have many ways. But if you can, use a way to check if there are an ace and a ten-value in the list.

```python
>>> blackjack(['A', 'K'])
True
>>> blackjack([10, 9])
False
```

[blackjack]: https://en.wikipedia.org/wiki/Blackjack
185 changes: 185 additions & 0 deletions exercises/concept/black-jack/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
## Comparisons

There are some different kinds of comparison operators in Python

| Operator | Operation | Description |
| -------- | ------------------------ | -------------------------------------------------------- |
| `>` | Greater than | `a > b` is `True` if `a` is greater than `b` |
| `<` | Less than | `a < b` is `True` if `a` is less than `b` |
| `==` | Equal to | `a == b` is `True` if `a` is equals to `b` |
| `>=` | Greater than or equal to | `a >= b` is `True` if `a > b` or `a == b` is `True` |
| `<=` | Less than or equal to | `a <= b` is `True` if `a < b` or `a == b` is `True` |
| `!=` | Not equal to | `a != b` is `True` if `a = b` is `False` |
| `is` | Identity | `a is b` is `True` if `a` and `b` is same object |
| `is not` | Identity | `a is not b` is `True` if `a` and `b` is not same object |
| `in` | Containment test | `a in b` is `True` if `a` is member of `b` |
| `not in` | Containment test | `a not in b` is `True` if `a` is not a member of `b` |

## Greater than

Operator `>` tests if the first operand's value is greater than the second one's.

```python
>>> 3 > 1
True
>>> 2.99 > 3
False
>>> 1 > 1
False
>>> 0 > 1
False
```

## Less than

Operator `<` tests if the first operand's value is less than the second one's.

```python
>>> 3 < 1
False
>>> 2.99 < 3
True
>>> 1 < 1
False
>>> 0 < 1
True
```

## Equal to

Operator `==` tests if the first operand's value is equal to the second one's

```python
>>> 3 == 1
False
>>> 2.99 == 3
False
>>> 1 == 1
True
>>> 0 == 1
False
```

## Greater than or equal to

Operator `>=` tests if the first operand's value is equal to or greater than the second one's.

```python
>>> 3 >= 1
True
>>> 2.99 >= 3
False
>>> 1 >= 1
True
>>> 0 >= 1
False
```

## Less than or equal to

Operator `<=` tests if the first operand's value is equal to or less than the second one's.

```python
>>> 3 <= 1
False
>>> 2.99 <= 3
True
>>> 1 <= 1
True
>>> 0 <= 1
True
```

## Not equal to

Operator `!=` tests if the first operand's value is not equal to the second one's

```python
>>> 3 != 1
True
>>> 2.99 != 3
True
>>> 1 != 1
False
>>> 0 != 1
True
```

## Identity test

Operator `is` tests if the first and second operand is the same object.

```python
# comparing non-object type `is` will raise warning
>>> 1 is 1
<stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
True
>>> 1 is 2
<stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
False
>>> x = int(4)
>>> y = x
>>> x is y
True
>>> y = int(5)
>>> x is y
False
```

Operator `is not` tests if the first and second operand is not the same object.

```python
>>> 1 is not 1
<stdin>:1: SyntaxWarning: "is not" with a literal. Did you mean "!="?
False
>>> 1 is not 2
<stdin>:1: SyntaxWarning: "is not" with a literal. Did you mean "!="?
True
>>> x = int(4)
>>> y = x
>>> x is not y
False
>>> y = int(5)
>>> x is not y
True
```

## Containment test

Operator `in` tests if the first operand is a member of the second operand.

```python
>>> x = [1, 2, 3, 4, 5]
>>> 1 in x
True
>>> 2 in x
True
>>> 3 in x
True
>>> 4 in x
True
>>> 5 in x
True
>>> 6 in x
False
```

Operator `not in` tests if the first operand is not a member of the second operand.

```python
>>> x = [1, 2, 3, 4, 5]
>>> 1 not in x
False
>>> 2 not in x
False
>>> 3 not in x
False
>>> 4 not in x
False
>>> 5 not in x
False
>>> 6 not in x
True
```

[python3-docs]: https://docs.python.org/3/library/operator.html
10 changes: 10 additions & 0 deletions exercises/concept/black-jack/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"blurb": "Learn about comparisons by implementing some Black Jack judging rules.",
"authors": ["Ticktakto", "Yabby1997", "limm-jk", "OMEGA-Y", "wnstj2007"],
"contributors": ["bethanyg"],
"files": {
"solution": ["black-jack.py"],
"test": ["black-jack_test.py"],
"exemplar": [".meta/exemplar.py"]
}
}
63 changes: 63 additions & 0 deletions exercises/concept/black-jack/.meta/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
## Goal

This concept exercise should teach how basic _non-customized_ comparisons work in python and how to use them effectively.

## Learning objectives

- understand all comparison operations in Python have the same priority and are evaluated after arithmetic, shifting, or bitwise operations.
- understand all comparisons yield the boolean values True and False
- know that identity comparisons is and is not are for checking an objects identity only
- understand that `==` and `!=` compare both the value & type of an object.
- know where Python has altered the behavior of `==` and `!=` for certain `built-in` types (such as [numbers][numbers], or for standard library types like [decimals][decimals], and [fractions][fractions] to allow comparison across and within type.
- know that unlike numeric types, strings (`str`) and binary sequences (`bytes` & `byte array`) **cannot** be directly compared.
- understand how comparisons work within `built-in` [sequence types][sequence types](`list`, `tuple`, `range`) and `built-in` `collection types` (`set`, `[dict]`)
- know about the "special" comparisons `None`, `NotImplemented` (comparing either should use identity operators and not equality operators because they are singleton objects) and NaN (`NaN` is **never** `==` to itself)
- use the value comparison operators `==`, `>`, `<`, `!=` with numeric types
- use the value comparison operators `==`, `>`, `<`, `!=` with non-numeric types
- use `is` and `is not` to check/verify identity

## Out of scope

- rich comparison with `__lt__`, `__le__`, `__ne__`, `__ge__`, `__gt__`
- understanding (_and using the concept_) that the `==` operator calls the dunder method `__eq__()` on a specific object, and uses that object's implementation for comparison. Where no implementation is present, the default `__eq__()` from generic `object` is used.
- overloading the default implementation of the `__eq__()` dunder method on a specific object to customize comparison behavior.
- `set operations`
- performance considerations

## Concepts

- Comparison priority in Python
- Comparison operators `==`, `>`, `<`, `!=`
- Identity methods `is` and `is not`
- Equality applied to `built-in` types
- Equivalence vs equality
- Inequality

## Prerequisites

- `basics`
- `booleans`
- `dicts`
- `lists`
- `sets`
- `strings`
- `tuples`
- `numbers`
- `iteration`

## Resources

- [Comparisons in Python (Python language reference)](https://docs.python.org/3/reference/expressions.html#comparisons)
- [Value comparisons in Python (Python language reference)](https://docs.python.org/3/reference/expressions.html#value-comparisons)
- [Identity comparisons in Python (Python language reference)](https://docs.python.org/3/reference/expressions.html#is-not)
- [Python operators official doc](https://docs.python.org/3/library/operator.html)
- [Python Object Model (Python docs)](https://docs.python.org/3/reference/datamodel.html#objects)
- [Basic Customization](https://docs.python.org/3/reference/datamodel.html#customization)
- [Python basic operators on tutorialspoint](https://www.tutorialspoint.com/python/python_basic_operators.htm)
- [Python comparison operators on data-flair](https://data-flair.training/blogs/python-comparison-operators/)
- [PEP 207 to allow Operator Overloading for Comparison](https://www.python.org/dev/peps/pep-0207/)

[numbers]: https://docs.python.org/3/library/stdtypes.html#typesnumeric
[decimals]: https://docs.python.org/3/library/decimal.html#decimal.Decimal
[fractions]: https://docs.python.org/3/library/fractions.html#fractions.Fraction
[sequence types]: https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range
23 changes: 23 additions & 0 deletions exercises/concept/black-jack/.meta/exemplar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def number_of_card(card):
if card == 'A':
return "ace"
elif card == 'J' or card == 'Q' or card == 'K':
return 10
else:
return card


def number_of_ace(hand):
if hand+11 <= 21:
return 11
else:
return 1


def blackjack(hand):
if 'A' not in hand:
return False
elif 'J' in hand or 'Q' in hand or 'K' in hand or 10 in hand:
return True
else:
False
10 changes: 10 additions & 0 deletions exercises/concept/black-jack/black-jack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def number_of_card(card):
pass


def number_of_ace(hand):
pass


def blackjack(hand):
pass
Loading