2019.03.09 - format method and X, E in multiplication table

This commit is contained in:
Fabian Scheuermann 2019-03-09 12:25:36 +01:00
parent 79a66e0de8
commit 715ed19227
2 changed files with 41 additions and 18 deletions

View File

@ -149,6 +149,9 @@ class duo:
return self.duodecimal[:7].rstrip('0') + '(base12)'
else:
return self.duodecimal + '(base12)'
def __str__(self):
return self.duodecimal
def __format__(self,format):
return self.duodecimal

View File

@ -159,34 +159,54 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\t1 \t2 \t3 \t4 \t5 \t6 \t7 \t8 \t9 \t10 \t11 \t12\n",
"\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",
"10| \tX \t18 \t26 \t34 \t42 \t50 \t5X \t68 \t76 \t84 \t92 \tX0\n",
"11| \tE \t1X \t29 \t38 \t47 \t56 \t65 \t74 \t83 \t92 \tX1 \tE0\n",
"12| \t10 \t20 \t30 \t40 \t50 \t60 \t70 \t80 \t90 \tX0 \tE0 \t100\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,13):\n",
" row = ['{:>2}|'.format(i)]\n",
" for j in range(1,13):\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(map(str,range(1,13)))+ '\\n'+99*'-')\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": {