-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiplicationTable.py
More file actions
24 lines (21 loc) · 882 Bytes
/
MultiplicationTable.py
File metadata and controls
24 lines (21 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#! python3
# Create a program multiplicationTable.py that takes a number N from the command line and creates an N×N
# multiplication table in an Excel spreadsheet.
import openpyxl
from openpyxl.styles import Font
def multiplicationTable(number):
wb = openpyxl.Workbook()
sheet = wb.active
boldFont = Font(bold=True)
for row in range(1, number+1):
sheet.cell(row=row+1, column=1).value = row
sheet.cell(row=row+1, column=1).font = boldFont
for col in range(1, number+1):
sheet.cell(row=1,column=col+1).value = col
sheet.cell(row=1, column=col+1).font = boldFont
for row in range(1, number+1):
for col in range(number + 1):
sheet.cell(row=row+1, column=col+1).value = row*col
wb.save('multiplicationTable.xlsx')
num = int(input('Enter the number: '))
multiplicationTable(num)