Multiplication table in html with python
#Generate multiplication table by html
#https://ideone.com/YVXmga
import random
from copy import deepcopy
N = 15
colors = ['F','E','D','C','B','A']
i = 0
colorsall = []
while i < N:
colornow = deepcopy(colors)
random.shuffle(colornow)
colornow = "#"+"".join(colornow)
colorsall.append(colornow)
i += 1
t = ""
for i in range(1,N+1):
s = ''
for j in range(1,N+1):
if j >= i:
s += '<td style="background-color:' + colorsall[i-1] + '">'+str(i*j)+'</td>'
else:
s += '<td style="background-color:' + colorsall[j-1] + '">'+str(i*j)+'</td>'
s = "<tr>" + s + "</tr>"
t = t + s + '\n'
print('<table>' + t + '</table>')
html code:
<table><tr><td style="background-color:#CFDBEA">1</td><td style="background-color:#CFDBEA">2</td><td style="background-color:#CFDBEA">3</td><td style="background-color:#CFDBEA">4</td><td style="background-color:#CFDBEA">5</td><td style="background-color:#CFDBEA">6</td><td style="background-color:#CFDBEA">7</td><td style="background-color:#CFDBEA">8</td><td style="background-color:#CFDBEA">9</td><td style="background-color:#CFDBEA">10</td><td style="background-color:#CFDBEA">11</td><td style="background-color:#CFDBEA">12</td><td style="background-color:#CFDBEA">13</td><td style="background-color:#CFDBEA">14</td><td style="background-color:#CFDBEA">15</td></tr>
<tr><td style="background-color:#CFDBEA">2</td><td style="background-color:#EFDCBA">4</td><td style="background-color:#EFDCBA">6</td><td style="background-color:#EFDCBA">8</td><td style="background-color:#EFDCBA">10</td><td style="background-color:#EFDCBA">12</td><td style="background-color:#EFDCBA">14</td><td style="background-color:#EFDCBA">16</td><td style="background-color:#EFDCBA">18</td><td style="background-color:#EFDCBA">20</td><td style="background-color:#EFDCBA">22</td><td style="background-color:#EFDCBA">24</td><td style="background-color:#EFDCBA">26</td><td style="background-color:#EFDCBA">28</td><td style="background-color:#EFDCBA">30</td></tr>
<tr><td style="background-color:#CFDBEA">3</td><td style="background-color:#EFDCBA">6</td><td style="background-color:#DFAECB">9</td><td style="background-color:#DFAECB">12</td><td style="background-color:#DFAECB">15</td><td style="background-color:#DFAECB">18</td><td style="background-color:#DFAECB">21</td><td style="background-color:#DFAECB">24</td><td style="background-color:#DFAECB">27</td><td style="background-color:#DFAECB">30</td><td style="background-color:#DFAECB">33</td><td style="background-color:#DFAECB">36</td><td style="background-color:#DFAECB">39</td><td style="background-color:#DFAECB">42</td><td style="background-color:#DFAECB">45</td></tr>
<tr><td style="background-color:#CFDBEA">4</td><td style="background-color:#EFDCBA">8</td><td style="background-color:#DFAECB">12</td><td style="background-color:#ADFECB">16</td><td style="background-color:#ADFECB">20</td><td style="background-color:#ADFECB">24</td><td style="background-color:#ADFECB">28</td><td style="background-color:#ADFECB">32</td><td style="background-color:#ADFECB">36</td><td style="background-color:#ADFECB">40</td><td style="background-color:#ADFECB">44</td><td style="background-color:#ADFECB">48</td><td style="background-color:#ADFECB">52</td><td style="background-color:#ADFECB">56</td><td style="background-color:#ADFECB">60</td></tr>
<tr><td style="background-color:#CFDBEA">5</td><td style="background-color:#EFDCBA">10</td><td style="background-color:#DFAECB">15</td><td style="background-color:#ADFECB">20</td><td style="background-color:#ADFCEB">25</td><td style="background-color:#ADFCEB">30</td><td style="background-color:#ADFCEB">35</td><td style="background-color:#ADFCEB">40</td><td style="background-color:#ADFCEB">45</td><td style="background-color:#ADFCEB">50</td><td style="background-color:#ADFCEB">55</td><td style="background-color:#ADFCEB">60</td><td style="background-color:#ADFCEB">65</td><td style="background-color:#ADFCEB">70</td><td style="background-color:#ADFCEB">75</td></tr>
<tr><td style="background-color:#CFDBEA">6</td><td style="background-color:#EFDCBA">12</td><td style="background-color:#DFAECB">18</td><td style="background-color:#ADFECB">24</td><td style="background-color:#ADFCEB">30</td><td style="background-color:#ECDABF">36</td><td style="background-color:#ECDABF">42</td><td style="background-color:#ECDABF">48</td><td style="background-color:#ECDABF">54</td><td style="background-color:#ECDABF">60</td><td style="background-color:#ECDABF">66</td><td style="background-color:#ECDABF">72</td><td style="background-color:#ECDABF">78</td><td style="background-color:#ECDABF">84</td><td style="background-color:#ECDABF">90</td></tr>
<tr><td style="background-color:#CFDBEA">7</td><td style="background-color:#EFDCBA">14</td><td style="background-color:#DFAECB">21</td><td style="background-color:#ADFECB">28</td><td style="background-color:#ADFCEB">35</td><td style="background-color:#ECDABF">42</td><td style="background-color:#BAFCDE">49</td><td style="background-color:#BAFCDE">56</td><td style="background-color:#BAFCDE">63</td><td style="background-color:#BAFCDE">70</td><td style="background-color:#BAFCDE">77</td><td style="background-color:#BAFCDE">84</td><td style="background-color:#BAFCDE">91</td><td style="background-color:#BAFCDE">98</td><td style="background-color:#BAFCDE">105</td></tr>
<tr><td style="background-color:#CFDBEA">8</td><td style="background-color:#EFDCBA">16</td><td style="background-color:#DFAECB">24</td><td style="background-color:#ADFECB">32</td><td style="background-color:#ADFCEB">40</td><td style="background-color:#ECDABF">48</td><td style="background-color:#BAFCDE">56</td><td style="background-color:#DFEBCA">64</td><td style="background-color:#DFEBCA">72</td><td style="background-color:#DFEBCA">80</td><td style="background-color:#DFEBCA">88</td><td style="background-color:#DFEBCA">96</td><td style="background-color:#DFEBCA">104</td><td style="background-color:#DFEBCA">112</td><td style="background-color:#DFEBCA">120</td></tr>
<tr><td style="background-color:#CFDBEA">9</td><td style="background-color:#EFDCBA">18</td><td style="background-color:#DFAECB">27</td><td style="background-color:#ADFECB">36</td><td style="background-color:#ADFCEB">45</td><td style="background-color:#ECDABF">54</td><td style="background-color:#BAFCDE">63</td><td style="background-color:#DFEBCA">72</td><td style="background-color:#EFCDBA">81</td><td style="background-color:#EFCDBA">90</td><td style="background-color:#EFCDBA">99</td><td style="background-color:#EFCDBA">108</td><td style="background-color:#EFCDBA">117</td><td style="background-color:#EFCDBA">126</td><td style="background-color:#EFCDBA">135</td></tr>
<tr><td style="background-color:#CFDBEA">10</td><td style="background-color:#EFDCBA">20</td><td style="background-color:#DFAECB">30</td><td style="background-color:#ADFECB">40</td><td style="background-color:#ADFCEB">50</td><td style="background-color:#ECDABF">60</td><td style="background-color:#BAFCDE">70</td><td style="background-color:#DFEBCA">80</td><td style="background-color:#EFCDBA">90</td><td style="background-color:#EADBCF">100</td><td style="background-color:#EADBCF">110</td><td style="background-color:#EADBCF">120</td><td style="background-color:#EADBCF">130</td><td style="background-color:#EADBCF">140</td><td style="background-color:#EADBCF">150</td></tr>
<tr><td style="background-color:#CFDBEA">11</td><td style="background-color:#EFDCBA">22</td><td style="background-color:#DFAECB">33</td><td style="background-color:#ADFECB">44</td><td style="background-color:#ADFCEB">55</td><td style="background-color:#ECDABF">66</td><td style="background-color:#BAFCDE">77</td><td style="background-color:#DFEBCA">88</td><td style="background-color:#EFCDBA">99</td><td style="background-color:#EADBCF">110</td><td style="background-color:#ECDAFB">121</td><td style="background-color:#ECDAFB">132</td><td style="background-color:#ECDAFB">143</td><td style="background-color:#ECDAFB">154</td><td style="background-color:#ECDAFB">165</td></tr>
<tr><td style="background-color:#CFDBEA">12</td><td style="background-color:#EFDCBA">24</td><td style="background-color:#DFAECB">36</td><td style="background-color:#ADFECB">48</td><td style="background-color:#ADFCEB">60</td><td style="background-color:#ECDABF">72</td><td style="background-color:#BAFCDE">84</td><td style="background-color:#DFEBCA">96</td><td style="background-color:#EFCDBA">108</td><td style="background-color:#EADBCF">120</td><td style="background-color:#ECDAFB">132</td><td style="background-color:#BDFCEA">144</td><td style="background-color:#BDFCEA">156</td><td style="background-color:#BDFCEA">168</td><td style="background-color:#BDFCEA">180</td></tr>
<tr><td style="background-color:#CFDBEA">13</td><td style="background-color:#EFDCBA">26</td><td style="background-color:#DFAECB">39</td><td style="background-color:#ADFECB">52</td><td style="background-color:#ADFCEB">65</td><td style="background-color:#ECDABF">78</td><td style="background-color:#BAFCDE">91</td><td style="background-color:#DFEBCA">104</td><td style="background-color:#EFCDBA">117</td><td style="background-color:#EADBCF">130</td><td style="background-color:#ECDAFB">143</td><td style="background-color:#BDFCEA">156</td><td style="background-color:#BAEDFC">169</td><td style="background-color:#BAEDFC">182</td><td style="background-color:#BAEDFC">195</td></tr>
<tr><td style="background-color:#CFDBEA">14</td><td style="background-color:#EFDCBA">28</td><td style="background-color:#DFAECB">42</td><td style="background-color:#ADFECB">56</td><td style="background-color:#ADFCEB">70</td><td style="background-color:#ECDABF">84</td><td style="background-color:#BAFCDE">98</td><td style="background-color:#DFEBCA">112</td><td style="background-color:#EFCDBA">126</td><td style="background-color:#EADBCF">140</td><td style="background-color:#ECDAFB">154</td><td style="background-color:#BDFCEA">168</td><td style="background-color:#BAEDFC">182</td><td style="background-color:#FCEDAB">196</td><td style="background-color:#FCEDAB">210</td></tr>
<tr><td style="background-color:#CFDBEA">15</td><td style="background-color:#EFDCBA">30</td><td style="background-color:#DFAECB">45</td><td style="background-color:#ADFECB">60</td><td style="background-color:#ADFCEB">75</td><td style="background-color:#ECDABF">90</td><td style="background-color:#BAFCDE">105</td><td style="background-color:#DFEBCA">120</td><td style="background-color:#EFCDBA">135</td><td style="background-color:#EADBCF">150</td><td style="background-color:#ECDAFB">165</td><td style="background-color:#BDFCEA">180</td><td style="background-color:#BAEDFC">195</td><td style="background-color:#FCEDAB">210</td><td style="background-color:#ABDFCE">225</td></tr>
</table>
Comments
Post a Comment