{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Lottery Game\n", "### Changing the Culture Conference" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from itertools import combinations\n", " \n", "def payoff(ticket, draw):\n", " \n", " # Count how many numbers appear on both the ticket\n", " # and the winning 3-number draw\n", " count=0\n", " for x in ticket:\n", " if x in draw:\n", " count+=1\n", " \n", " # If 3 numbers match, return $210. If 2 numbers match, return $70\n", " if count==3: return 210\n", " elif count==2: return 70\n", " else: return 0\n", "\n", "def profit(alltickets, draw):\n", " \n", " # You pay 200 dollars at the start\n", " winnings = -200\n", "\n", " # For each ticket, add the payoff to the total winnings\n", " for ticket in alltickets:\n", " winnings += payoff(ticket, draw)\n", " return winnings\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "T1=[1,2,3]\n", "T2=[1,4,5]\n", "T3=[1,6,7]\n", "T4=[2,4,6]\n", "T5=[2,5,7]\n", "T6=[3,5,6]\n", "T7=[3,4,7]\n", "OurTickets = [T1,T2,T3,T4,T5,T6,T7]" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(1, 2, 3) is a profit of 10\n", "(1, 2, 4) is a profit of 10\n", "(1, 2, 5) is a profit of 10\n", "(1, 2, 6) is a profit of 10\n", "(1, 2, 7) is a profit of 10\n", "(1, 3, 4) is a profit of 10\n", "(1, 3, 5) is a profit of 10\n", "(1, 3, 6) is a profit of 10\n", "(1, 3, 7) is a profit of 10\n", "(1, 4, 5) is a profit of 10\n", "(1, 4, 6) is a profit of 10\n", "(1, 4, 7) is a profit of 10\n", "(1, 5, 6) is a profit of 10\n", "(1, 5, 7) is a profit of 10\n", "(1, 6, 7) is a profit of 10\n", "(2, 3, 4) is a profit of 10\n", "(2, 3, 5) is a profit of 10\n", "(2, 3, 6) is a profit of 10\n", "(2, 3, 7) is a profit of 10\n", "(2, 4, 5) is a profit of 10\n", "(2, 4, 6) is a profit of 10\n", "(2, 4, 7) is a profit of 10\n", "(2, 5, 6) is a profit of 10\n", "(2, 5, 7) is a profit of 10\n", "(2, 6, 7) is a profit of 10\n", "(3, 4, 5) is a profit of 10\n", "(3, 4, 6) is a profit of 10\n", "(3, 4, 7) is a profit of 10\n", "(3, 5, 6) is a profit of 10\n", "(3, 5, 7) is a profit of 10\n", "(3, 6, 7) is a profit of 10\n", "(4, 5, 6) is a profit of 10\n", "(4, 5, 7) is a profit of 10\n", "(4, 6, 7) is a profit of 10\n", "(5, 6, 7) is a profit of 10\n", "\n", "The average profit is 10.0 dollars\n", "The team makes a profit 35 out of 35 times\n" ] } ], "source": [ "expected = 0\n", "wins=0\n", " \n", "for draw in combinations([1,2,3,4,5,6,7],3):\n", " \tresult = profit([T1,T2,T3,T4,T5,T6,T7], draw)\n", " \texpected += result/35\n", " \tif result>0: wins += 1\n", " \tprint(draw, \"is a profit of\", result)\n", " \t\n", "print(\"\")\n", "print(\"The average profit is\", round(expected, 4), \"dollars\")\n", "print(\"The team makes a profit\", wins, \"out of 35 times\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.12.7" } }, "nbformat": 4, "nbformat_minor": 4 }