Skip to content
Open
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
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# Created by https://www.toptal.com/developers/gitignore/api/jupyternotebooks
# Edit at https://www.toptal.com/developers/gitignore?templates=jupyternotebooks

### JupyterNotebooks ###
# gitignore template for Jupyter Notebooks
# website: http://jupyter.org/

.ipynb_checkpoints
*/.ipynb_checkpoints/*

# IPython
profile_default/
ipython_config.py

# Remove previous ipynb_checkpoints
# git rm -r .ipynb_checkpoints/

# End of https://www.toptal.com/developers/gitignore/api/jupyternotebooks
180 changes: 180 additions & 0 deletions your-project/Draft 2.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['1 of clubs', '1 of diamonds', '1 of heart', '1 of spades', '2 of clubs', '2 of diamonds', '2 of heart', '2 of spades', '3 of clubs', '3 of diamonds', '3 of heart', '3 of spades', '4 of clubs', '4 of diamonds', '4 of heart', '4 of spades', '5 of clubs', '5 of diamonds', '5 of heart', '5 of spades', '6 of clubs', '6 of diamonds', '6 of heart', '6 of spades', '7 of clubs', '7 of diamonds', '7 of heart', '7 of spades', '8 of clubs', '8 of diamonds', '8 of heart', '8 of spades', '9 of clubs', '9 of diamonds', '9 of heart', '9 of spades', '10 of clubs', '10 of diamonds', '10 of heart', '10 of spades', 'J of clubs', 'J of diamonds', 'J of heart', 'J of spades', 'Q of clubs', 'Q of diamonds', 'Q of heart', 'Q of spades', 'K of clubs', 'K of diamonds', 'K of heart', 'K of spades']\n"
]
}
],
"source": [
"suits=(\"clubs\",\"diamonds\",\"heart\",\"spades\")\n",
"values=(\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"J\",\"Q\",\"K\")\n",
"deck=[]\n",
"for value in values:\n",
" for suit in suits:\n",
" deck.append(value +\" of \"+ str(suit)) \n",
"print(deck)"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"def card_value(card):\n",
" if card[0] in (\"J\",\"Q\",\"K\"):\n",
" return int(10)\n",
" elif card[0] in (\"A\"):\n",
" return int(1)\n",
" elif card[0] in (\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\"):\n",
" return int(card[0])\n",
" \n",
"player_value=0\n",
"dealer_value=0"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['6 of spades', '5 of spades']\n",
"6\n",
"11\n",
"Would you like another card? Yes\n"
]
}
],
"source": [
"player_hand=random.sample(deck,2)\n",
"print(player_hand)\n",
"for card in player_hand:\n",
" player_value += card_value(card)\n",
" print(player_value)\n",
"if player_value==21:\n",
" print(\"Congratulations it's a Blackjack!\")\n",
"else:\n",
" answer= input(\"Would you like another card? \")\n"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['6 of spades', '5 of spades', 'K of diamonds']\n",
"17\n",
"22\n",
"32\n",
"Oh, you have lost! Try next time\n",
"['4 of spades', '5 of heart']\n",
"9\n",
"['6 of diamonds', '9 of diamonds']\n",
"24\n",
"['Q of heart', '2 of diamonds']\n",
"36\n",
"['K of spades', '3 of diamonds']\n",
"49\n",
"['Q of clubs', '7 of spades']\n",
"66\n",
"['K of clubs', 'Q of heart']\n",
"86\n",
"['3 of clubs', 'K of clubs']\n",
"99\n",
"['1 of clubs', 'Q of diamonds']\n"
]
},
{
"ename": "TypeError",
"evalue": "unsupported operand type(s) for +=: 'int' and 'NoneType'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-46-7b3de8d6b327>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 20\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdealer_hand\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 21\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mcard\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mdealer_hand\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 22\u001b[1;33m \u001b[0mdealer_value\u001b[0m \u001b[1;33m+=\u001b[0m \u001b[0mcard_value\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcard\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 23\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdealer_value\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 24\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for +=: 'int' and 'NoneType'"
]
}
],
"source": [
"while True:\n",
" if answer == \"Yes\":\n",
" player_hand.append(random.sample(deck,1)[0])\n",
" print(player_hand)\n",
" for card in player_hand:\n",
" player_value += card_value(card) \n",
" print(player_value)\n",
" if player_value == 21:\n",
" print(\"Congratulations, it's a BlackjacK!\")\n",
" elif player_value>21:\n",
" print(\"Oh, you have lost! Try next time\")\n",
" break\n",
" \n",
" elif answer == \"No\":\n",
" \n",
" break\n",
" \n",
"while True:\n",
" dealer_hand=random.sample(deck,2)\n",
" print(dealer_hand)\n",
" for card in dealer_hand:\n",
" dealer_value += card_value(card)\n",
" print(dealer_value)\n",
" \n",
" \n",
"\n",
"if dealer_value==player_value== 21:\n",
" print(\"It's a tie!\")\n",
"elif player_value<dealer_value:\n",
" print(\"Oh, you have lost! Try next time\")\n",
"elif player_value>dealer_value<21:\n",
" print(\"Oh, you have lost! Try next time\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
145 changes: 145 additions & 0 deletions your-project/Draft 3.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First of all define each object we will use for the game loop:\n",
"\n",
"- Card(and value of each card)\n",
"\n",
"- Deck of 52 cards\n",
"\n",
"- Player hand (2 or 3 cards)\n",
"\n",
"- Dealers hand (2 or 3 cards)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then we define:\n",
"- the first mix and deal to the players\n",
"- players pass or asks\n",
"- players busts\n",
"- mix and deal to the dealer\n",
"- dealer face up second card and pass or asks\n",
"- dealer busts\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Once we have all the objects we can start the loop of the game\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"suits=(\"clubs\",\"diamonds\",\"heart\",\"spades\")\n",
"values=(\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"J\",\"Q\",\"K\")\n",
"deck=[]\n",
"absolute_values={\"A\":\"1\",\"J\":\"10\",\"Q\":\"10\",\"K\":\"10\"}\n",
"\n",
"for value in values:\n",
" for suit in suits:\n",
" deck.append(value +\" of \"+ str(suit)) \n",
"print(deck)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def card_value(card):\n",
" if card[0] in (\"J\",\"Q\",\"K\"):\n",
" return int(10)\n",
" elif card[0] in (\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\"):\n",
" return int(card[0])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"player_hand=[]\n",
"dealer_hand=[]\n",
"player_value=0\n",
"dealer_value=0\n",
"\n",
"player_hand.append(random.sample(deck,2))\n",
"print(player_hand)\n",
"\n",
"for card in player_hand:\n",
" player_value += card_value(card)\n",
"print(player_hand)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if player_value == 21:\n",
" print(\"Congratulations you hit the pot!\")\n",
"else:\n",
" print (\"Hit?\")\n",
" answer=input()\n",
"if answer == \"Yes\":\n",
" player_hand.append(random.sample(deck,1))\n",
"else:\n",
" dealer_hand.append(random.sample(deck,2))\n",
" if dealer_value == 21:\n",
" print(\"The dealer has won!\")\n",
" else:\n",
" print (\"Hit?\")\n",
" answer=input()\n",
" if answer == \"Yes\":\n",
" dealer_hand.append(random.sample(deck,1))\n",
" else:\n",
" print(\"Face up the cards\")\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading