CS
Just some hand-writing notes Still updating…
The reason I chose hand-writing instead of typing is that, I’ve just finished my High Shcool learning and I’ve been using hand-writing notes for years. It’s more convenient for myself, but maybe not so friendly to others. Sorry about this!
Maybe later in CSC courses I will try to use typing to note, after my $\LaTeX$ learning.
MAT1001 Calculus I This is the first note I’ve done in CUHKSZ, so it may be a bit messy. The notes later will be more formal and tidy (I guess).
MAT1002 Calculus II Unfinished
MAT2041 Linear Algebra and Applications Unfinished
STA2001 Probability and Statistics I Unfinished
Python Code
Generated by Deepseek
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 import osimport zipfilefrom PIL import Imagefrom fpdf import FPDFimport globdef zip_to_pdf (zip_path, output_folder=None ): """ 将ZIP文件中的JPG图片合并为PDF 参数: zip_path (str): ZIP文件路径 output_folder (str, optional): 输出PDF的目录,默认为ZIP所在目录 """ if not os.path.exists(zip_path): raise FileNotFoundError(f"ZIP文件不存在: {zip_path} " ) if output_folder is None : output_folder = os.path.dirname(zip_path) zip_name = os.path.splitext(os.path.basename(zip_path))[0 ] pdf_path = os.path.join(output_folder, f"{zip_name} .pdf" ) temp_dir = os.path.join(output_folder, f"temp_{zip_name} " ) os.makedirs(temp_dir, exist_ok=True ) try : with zipfile.ZipFile(zip_path, 'r' ) as zip_ref: zip_ref.extractall(temp_dir) jpg_files = glob.glob(os.path.join(temp_dir, "*.jpg" )) + glob.glob(os.path.join(temp_dir, "*.jpeg" )) if not jpg_files: raise ValueError("ZIP文件中没有找到JPG图片" ) jpg_files.sort() pdf = FPDF(unit="pt" ) for jpg_file in jpg_files: with Image.open (jpg_file) as img: width, height = img.size pdf.add_page(format =[width, height]) pdf.image(jpg_file, x=0 , y=0 , w=width, h=height) pdf.output(pdf_path) print (f"成功创建PDF: {pdf_path} " ) finally : import time time.sleep(1 ) for root, dirs, files in os.walk(temp_dir, topdown=False ): for name in files: file_path = os.path.join(root, name) try : os.remove(file_path) except PermissionError: print (f"无法删除文件 {file_path} ,可能仍被占用" ) for name in dirs: os.rmdir(os.path.join(root, name)) try : os.rmdir(temp_dir) except OSError: print (f"无法删除临时目录 {temp_dir} ,可能仍有文件被占用" ) if __name__ == "__main__" : zip_file = input ("请输入ZIP文件路径: " ).strip('"\' ' ) zip_to_pdf(zip_file)