[Teaching-29-03] 20230409 “House Number – Sticky Edition (5 layers * 5 rooms) underlined on gray background” – (Middle class “I Love My Home” partial mathematics)

Article style:

Background requirements

In the teaching practice of the sticky version of the house number, it was found that 90% of the children could not do

1. Spaces are not evenly distributed:

From the house number of 5*6=30, 5 blanks are randomly selected, and there is an 80% probability that “one row has 2 blanks, and 3 rows has 1 blank”. But it is the first time for young children to do it, and the floor is not clear, and it is even more difficult to understand the concept of “room” (two spaces and two rooms in a row).

Required: one space for each floor, understand the concept of “floor”

Design the exercise of “5 blank stickers for the house number”. 5*5 buildings, randomly empty one grid in each row, and ensure that each column is also empty. Let the children paste and identify the unique space on each floor from the first three-digit number (floor, floor).

2. It is difficult to identify the pasting position:

In the process of analyzing the correct rate of children’s pasting, I found that it is difficult to see which ones are pasted through photos – many children pasted digital pasting cards and blank cards at the same time, and the number was too large. There are many, and it is hard to see which ones are digital stickers; even if some stickers with printed numbers are pasted in the building, against the white background and similar numbers, they look exactly the same as the surrounding numbers.

Therefore, when checking the correctness, the teacher had to touch the original works of the children, observe them one by one, and peel off the pieces of paper to confirm which pieces were pasted.

After cutting out a large number of pasted stickers, the child No. 22 did not know the direction of the numbers, so they pasted them vertically.

Need: Optimize the details and paste the card, easy to identify

1. The background of the sticky card is set to gray, which is convenient for teachers to know which spaces are for children to post.

2. Paste the card underline the numbers to help children determine the direction of pasting (the underline is below)

Design process:

1. Material preparation:

Word Settings

2. Code description

#'''
# author:Asha
# Principle: House number 5*6=30. Extract 15 blanks, and fill the second table with the contents of 15 blanks (cut and paste in the blanks).
# Result: House number Paste version (suitable for middle class)
# Time: 2023-4-7 13:31
#'''
import random




print('---------Part 2 form in word----------')

num=int(input('How many copies to generate (enter 28 according to the class size, and actually print 14 copies)\
'))
# Number=int(input('randomly draw a few numbers (5)\
'))
size=float(input('number size (35)\
'))
height1=int(input('Room table height (6 floors)\
'))
weight1=int(input('room form width (5 rooms)\
'))


# room table position
bg1=[]
for x1 in range(height1-1,-1,-1): # The first row of the table is 601\602, and the bottom row is 101 102, so the index needs to subtract 1=5 from large to small height1=6, 0 needs to be subtracted from 1 =-1 (50 51------00 01)
    for y1 in range(0,weight1):
        ww1='{}{}'.format(x1,y1)
        bg1.append(ww1)
print(bg1)
# ['50', '51', '52', '53', '54', '40', '41', '42', '43', '44', '30', '31', '32', '33', '34', '20', '21', '22', '23', '24', '10', '11', '12', '13', '14 ', '00', '01', '02', '03', '04']
# Among them, the first 25 are room numbers, and the last 5 are stickers

# Random array such as 01234 20134 etc.
# P=[]
# for s1 in range(0, 5):
# for s2 in range(0, 5):
# for s3 in range(0, 5):
# for s4 in range(0, 5):
# for s5 in range(0, 5):
# if s1 != s2 and s1 != s3 and s1 != s4 and s1 != s5 and s2 !=s3 and s2!=s4 and s2!=s5 and s3!=s4 and s3!=s5 and s4!= s5:
# print(s1,s2,s3,s4,s5)
# # # s2=str(s1) + str(s2) + str(s3) + str(s4) + str(s5)
# ss='{}{}{}{}{}'.format(s1,s2,s3,s4,s5)
# P.append(ss)
## P.append(s2)
# print(len(P))

print('---------Part 3, write randomly selected questions in the word cell, batch N copies of word, and convert it to pdf----------')

import random
from win32com.client import constants, gencache
from win32com.client.gencache import EnsureDispatch
from win32com.client import constants # Import enumeration constant module
import os,time

import docx
from docx import Document
from docx.shared import Pt
from docx.shared import RGBColor
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx.oxml.ns import qn


from docxtpl import DocxTemplate
import pandas as pd
from docx2pdf import convert
from docx.shared import RGBColor


# Create a new temporary folder for "installing N copies of word and PDF"
os.mkdir(r'C:\Users\jg2yXRZ\OneDrive\Desktop\Paste House Number\Zero Hour Word')

n=int(num/2)
for z in range(0,n): #how many copies
    # new word
    doc = Document(r'C:\Users\jg2yXRZ\OneDrive\Desktop\Paste house number\Paste house number template vertical version 2 copies (6 floors and 5 rooms).docx')
    for j in range(2):
    
        # make "room number"
        N=[]
        for x in range(1, height1):
            for y in range(1,weight1 + 1):
                s1='{}{}'.format(x,' d'%y) # numbers plus spaces
                N.append(s1)
        print(N)
    # ['101', '102', '103', '104', '105', '201', '202', '203', '204', '205', '301', '302', '303', '304', '305', '401', '402', '403', '404', '405', '501', '502', '503', '504', '505 ']

        # Turn the list into five groups
        E=[]
        for e in range(height1-1):
            E.append(N[e*weight1:e*weight1 + weight1])
        print(E)
        # [['101', '102', '103', '104', '105'], ['201', '202', '203', '204', '205'], ['301' , '302', '303', '304', '305'], ['401', '402', '403', '404', '405'], ['501', '502', ' 503', '504', '505']]

        # Extract the empty position of each line, such as 01234 20134, etc.
        from itertools import permutations
        A=list(permutations('01234'))
        print(list(permutations('01234')))
        print(len(A))
        # [('4', '3', '2', '0', '1'), ('4', '3', '2', '1', '0')]

        # Index numbers Randomly select a set of index numbers
        C=random. sample(A,1)
        print(C)

        S=[]
        for i in C:
            for k in i:
                print(k)
                S.append(k)
        print(S)
        # ['0', '1', '3', '4', '2']

        

        # Randomly draw 15 numbers from the house number list (this kind of extraction method will have 3 01 and 2 02, and I need the columns with 5 vacant numbers in each row to be in different positions.)
        # G=[]
        # for f in range(weight1):
        # C=random. sample(E[f],Number)
        # # Randomly draw an empty space among the first group of five numbers
        # for h in C:
        # G.append(h)
        # print(G)

        # Extract 5 combinations of the house number E of the specified index, and replace a number in each
        G=[]
        for p in range(weight1): # '3', '2', '1', '0', '4'
            q=int(S[p]) # index number integer, 3 2 1 0 4
            C=E[p][q] # The extracted group index is 01234, the number of each element is selected
            print(C)
            G.append(C)
        print(G) # ['104', '203', '302', '401', '505']



        # Room template (the first form) replaces the extracted room number with _
        C1=[]
        for tt in range(len(N)):
            for a2 in range(len(G)):
                if N[tt]==G[a2]:
                    N[tt]=' '
        for a5 in N:
            C1.append(a5)
        N. clear()
        C1.append(a5)
        print(C1)
        
    
        # # Merge the extracted 5 house numbers (write first) + vacancy combination (5 lines)
        # B1=G + C1
        #print(B1)
    

        # List of house numbers to be written in the room template (the first table)
        table = doc. tables[j]
        
        for t1 in range(0,len(bg1[5:])): # 0-5 is the bottom line, used to write card numbers
            pp1=int(bg1[5:][t1][0]) #
            qq1=int(bg1[5:][t1][1])
            k1=C1[t1] # Extract each graphic in the list pattern list t=index number
            print(pp1,qq1,k1)

            run=table.cell(pp1,qq1).paragraphs[0].add_run(k1) # Enter the 0th graph pattern in cell 0,0 (row 1, column 1)
            run.font.name = 'Chinese Xinwei'#The default Chinese color cloud font when inputting
            run.font.size = Pt(size) #Input font size defaults to 30
            run.font.color.rgb = RGBColor(200,200,200) #The number is small, the color depth is 0-255
            run.font.underline = False # underline
            # paragraph.paragraph_format.line_spacing = Pt(180) #Number paragraph spacing

            r = run._element
            r.rPr.rFonts.set(qn('w:eastAsia'), 'Chinese Xinwei')#Change the Chinese font in the input sentence to Chinese Xingkai
            table.cell(pp1,qq1).paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.CENTER #Center

        for t2 in range(0,len(bg1[0:5])): # 0-5 is the bottom line, used to write card numbers
            pp2=int(bg1[0:5][t2][0]) #
            qq2=int(bg1[0:5][t2][1])
            k2=G[t2] # Extract each graphic in the list pattern list t=index number
            print(pp2,qq2,k2)

            run=table.cell(pp2,qq2).paragraphs[0].add_run(k2) # Enter the 0th graph pattern in cell 0,0 (row 2, column 2)
            run.font.name = 'Chinese Xinwei'#The default Chinese color cloud font when inputting
            run.font.size = Pt(size) #Input font size defaults to 30
            run.font.color.rgb = RGBColor(200,200,200) #The number is small, the color depth is 0-255
            run.font.underline = True # underline
            # paragraph.paragraph_format.line_spacing = Pt(280) #Number paragraph spacing

            r = run._element
            r.rPr.rFonts.set(qn('w:eastAsia'), 'Chinese Xinwei')#Change the Chinese font in the input sentence to Chinese Xingkai
            table.cell(pp2,qq2).paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.CENTER #Center
    
#
    doc.save(r'C:\Users\jg2yXRZ\OneDrive\Desktop\Paste House Number\Zero Hour Word\{}.docx'.format(' d'%(z + 1)))#Save as XX student number phone number word

    from docx2pdf import convert
    # Save the docx file as a PDF file
    inputFile = r"C:/Users/jg2yXRZ/OneDrive/Desktop/Paste House Number/Zero Hour Word/{}.docx".format(' d'%(z + 1))# File to be converted: Already exist
    outputFile = r"C:/Users/jg2yXRZ/OneDrive/Desktop/Paste House Number/Zero Hour Word/{}.pdf".format(' d'%(z + 1)) # File to be generated: no exist
    # Create the non-existing file first
    f1 = open(outputFile, 'w')
    f1. close()
    # Then convert to write content in PDF
    convert(inputFile, outputFile)
    
print('----------Step 4: Merge all PDFs into one PDF for printing------------')
    
# Merge multiple PDFs (CSDN blogger "Red Little Crab", https://blog.csdn.net/yangcunbiao/article/details/125248205)
import os
from PyPDF2 import PdfFileMerger
target_path = 'C:/Users/jg2yXRZ/OneDrive/Desktop/Paste House Number/Zero Hour Word'
pdf_lst = [f for f in os.listdir(target_path) if f.endswith('.pdf')]
pdf_lst = [os.path.join(target_path, filename) for filename in pdf_lst]
pdf_lst. sort()
file_merger = PdfFileMerger()
for pdf in pdf_lst:
    print(pdf)
    file_merger.append(pdf)
file_merger.write("C:/Users/jg2yXRZ/OneDrive/Desktop/Paste House Number/(Print Collection) Paste House Number (two copies per page, 1 space per line) {} times {}({} copies) .pdf".format(height1,weight1,n))

file_merger. close()
# doc. Close()

# # print('----------Step 5: Delete the temporary folder ------------')
import shut-off
shutil.rmtree('C:/Users/jg2yXRZ/OneDrive/Desktop/Paste House Number/Zero Time Word') #Delete folders recursively, ie: delete non-empty folders


Code highlights:

Terminal operation:

Works display:

1. Each copy has one empty grid in one row and one empty grid in each column, and the vacant positions of all learning tools are different.

2. Make sure that the sticky card has a gray background and is underlined-it is easy for teachers and children to identify

Sentiment:

Python’s list, random selection, index value and other content can provide hierarchical learning tools for kindergarten partial number learning activities, learn some key methods, and can be based on children’s general level (“We can’t do it” ) to design digital paper learning tools that are less difficult (one line and one blank), clearer goals (knowing that the first number is the floor), and more convenient to operate (smaller learning tools area)