fschmnn-duodecimal/example_usage.ipynb

234 lines
4.6 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Example usage of the duo class\n",
"\n",
"## Basic operations"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from duodecimal import duo"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"36(base12)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"duo(42)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"24(base12)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"duo('24')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5X(base12)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = duo(42)\n",
"b = duo(28)\n",
"\n",
"a + b"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"12(base12)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a - b"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1(base12)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"duo(3) * 4"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.4(base12)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"duo(10) / '3'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create a multiplication table"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\t1 \t2 \t3 \t4 \t5 \t6 \t7 \t8 \t9 \tX \tE \t10\n",
"---------------------------------------------------------------------------------------------------\n",
"1| \t1 \t2 \t3 \t4 \t5 \t6 \t7 \t8 \t9 \tX \tE \t10\n",
"2| \t2 \t4 \t6 \t8 \tX \t10 \t12 \t14 \t16 \t18 \t1X \t20\n",
"3| \t3 \t6 \t9 \t10 \t13 \t16 \t19 \t20 \t23 \t26 \t29 \t30\n",
"4| \t4 \t8 \t10 \t14 \t18 \t20 \t24 \t28 \t30 \t34 \t38 \t40\n",
"5| \t5 \tX \t13 \t18 \t21 \t26 \t2E \t34 \t39 \t42 \t47 \t50\n",
"6| \t6 \t10 \t16 \t20 \t26 \t30 \t36 \t40 \t46 \t50 \t56 \t60\n",
"7| \t7 \t12 \t19 \t24 \t2E \t36 \t41 \t48 \t53 \t5X \t65 \t70\n",
"8| \t8 \t14 \t20 \t28 \t34 \t40 \t48 \t54 \t60 \t68 \t74 \t80\n",
"9| \t9 \t16 \t23 \t30 \t39 \t46 \t53 \t60 \t69 \t76 \t83 \t90\n",
"X| \tX \t18 \t26 \t34 \t42 \t50 \t5X \t68 \t76 \t84 \t92 \tX0\n",
"E| \tE \t1X \t29 \t38 \t47 \t56 \t65 \t74 \t83 \t92 \tX1 \tE0\n",
"10| \t10 \t20 \t30 \t40 \t50 \t60 \t70 \t80 \t90 \tX0 \tE0 \t100\n"
]
}
],
"source": [
"multiplication_table = []\n",
"for i in range(1,duo('10').dec()+1):\n",
" row = ['{:>2}|'.format(duo(i))]\n",
" for j in range(1,duo('10').dec()+1):\n",
" row.append(duo(i*j).__str__())\n",
" multiplication_table.append(row)\n",
"print('\\t'+' \\t'.join([str(duo(i)) for i in range(1,duo('10').dec()+1)]) + '\\n'+99*'-')\n",
"for row in multiplication_table:\n",
" print(' \\t'.join(row))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"duo('X').dec()"
]
}
],
"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.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}