Question 24Write a Python function that will output the twelve months (i.e., January, February...) in a HTML table one month per row. The rows will have alternating bold and normalfont.
Answers
Explanation:
A drug is any substance (with the exception of food and water) which, when taken into the body, alters the body’s function either physically and/or psychologically. Drugs may be legal (e.g. alcohol, caffeine and tobacco) or illegal (e.g. cannabis, ecstasy, cocaine and heroin).
It has the input file that consists of months in tables format one month per row.
The rows have alternating bold and normal font.
Explanation:
HTML
<table>
<tr>
<th>Serial No.</th>
<th>Month Name</th>
</tr>
<tr>
<td>1</td>
<td>January</td>
</tr>
<td>1</td><i>
<td>February</td>
</tr></i>
<td>1</td>
<td>March</td>
</tr>
<td>1</td><i>
<td>April</td>
</tr></i>
<td>1</td>
<td>May</td>
</tr>
<td>1</td><i>
<td>June</td>
</tr></i>
<td>1</td>
<td>July</td>
</tr>
<td>1</td><i>
<td>August</td>
</tr></i>
<td>1</td>
<td>September</td>
</tr>
<td>1</td><i>
<td>October</td>
</tr></i>
<td>1</td>
<td>November</td>
</tr>
<td>1</td><i>
<td>December</td>
</tr></i>
</table>
import sys
filein = open(sys.argv[1], "r")
fileout = open("html-table.html", "w")
data = filein.readlines()
table = "<table>\n"
header = data[0].split(",")
table += " <tr>\n"
for column in header:
table += " <th>{0}</th>\n".format(column.strip())
table += " </tr>\n"
for line in data[1:]:
row = line.split(",")
table += " <tr>\n"
for column in row:
table += " <td>{0}</td>\n".format(column.strip())
table += " </tr>\n"
table += "</table>"
fileout.writelines(table)
fileout.close()
filein.close(