{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import random as random" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def card():\n", " pack ={} #empty dictionary\n", " x=[] # empty list for card\n", " y=[] # empty list for shape\n", " z=[] # empty list for color\n", " for i in range(3): # for 3 card \n", " cd = random.choice(['A','2','3','4','5','6','7','8','9','10','J','Q','K'])\n", " x.append(cd)\n", " s = random.choice(['Diamond', 'Spade', 'Club','Heart'])\n", " y.append(s)\n", " if(s=='Diamond' or s=='Heart'):\n", " c='Red'\n", " else:\n", " c='Black' \n", " z.append(c) \n", " pack.update({'Card':x,'Shape':y,'Color':z})\n", " return pack" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'Card': ['4', 'K', 'Q'],\n", " 'Shape': ['Diamond', 'Spade', 'Spade'],\n", " 'Color': ['Red', 'Black', 'Black']}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data=card()\n", "data" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
CardShapeColor
04DiamondRed
1KSpadeBlack
2QSpadeBlack
\n", "
" ], "text/plain": [ " Card Shape Color\n", "0 4 Diamond Red\n", "1 K Spade Black\n", "2 Q Spade Black" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "DF=pd.DataFrame(data)\n", "DF" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'K'" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "DF.Card[1]" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Spade'" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "DF.Shape[2]" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Red'" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "DF.Color[0]" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "you win Rs 50\n" ] } ], "source": [ "if(DF.Card[0]==DF.Card[1] and DF.Card[1]==DF.Card[2]): #3 same card\n", " if(DF.Card[0]=='A'):\n", " print('Congratulation! You win Rs 800')\n", " elif(DF.Card[0]=='K'):\n", " print('Congratulation! You win Rs 700')\n", " else:\n", " print('You win Rs 600')\n", " \n", "elif(DF.Shape[0]==DF.Shape[1] and DF.Shape[1]==DF.Shape[2]): #3 same shape\n", " print('You win Rs 500')\n", " \n", "elif(DF.Card[0]==DF.Card[1] or DF.Card[1]==DF.Card[2] or DF.Card[0]==DF.Card[2]):#2 same card\n", " if(DF.Shape[0]==DF.Shape[1] and DF.Shape[1]==DF.Shape[2]): #3 same shape\n", " print('You win Rs 300')\n", " elif(DF.Shape[0]==DF.Shape[1] or DF.Shape[1]==DF.Shape[2] or DF.Shape[0]==DF.Shape[2]):# 2 same shape\n", " print('You win Rs 200')\n", " else:\n", " print('you win Rs 100') \n", " \n", "elif(DF.Shape[0]==DF.Shape[1] or DF.Shape[1]==DF.Shape[2] or DF.Shape[0]==DF.Shape[2]):# 2 same shape\n", " if(DF.Color[0]==DF.Color[1] and DF.Color[1]==DF.Color[2]): # 3 same color \n", " print('You win Rs 80')\n", " else:\n", " print('you win Rs 50') \n", " \n", "elif(DF.Color[0]==DF.Color[1] and DF.Color[1]==DF.Color[2]): # 3 same color \n", " print('You win Rs 20') \n", "else:\n", " print('you loss Rs 100')" ] }, { "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.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }