Skip to content

Latest commit

 

History

History

Computer-Programming

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

COM 1305 Computer Programming

Type Tech

"Mastering Logic, Automation, and Problem Solving"


🎯 เกี่ยวกับรายวิชา

รายวิชานี้เป็นจุดเริ่มต้นของการเขียนโปรแกรม สำหรับนักศึกษาวิทยาการคอมพิวเตร์ทุกคน มุ่งเน้นการพัฒนา Computational Thinking หรือกระบวนการคิดเชิงคำนวณ เพื่อฝึกให้สามารถแก้ปัญหาได้อย่างเป็นระบบ

ใช้ภาษา Python เป็นสื่อในการเรียนรู้ เนื่องจาก:

  • Syntax กระชับ: อ่านเข้าใจง่าย คล้ายภาษาอังกฤษทั่วไป
  • ไม่ซับซ้อน: ไม่ต้องกังวลเรื่อง Type Declaration หรือ Memory Management
  • เหมาะกับผู้เริ่มต้น: สามารถมองเห็นผลลัพธ์ได้ทันที

เนื้อหาหลักที่เรียน

  1. Basic Syntax - Variables, Data Types, Operators
  2. Control Flow - Conditional Statements (if-else), Loops (for, while)
  3. Data Structures - List, Dictionary, Tuple, Set
  4. Functions - การสร้างฟังก์ชันและการเรียกใช้งาน
  5. File I/O - การอ่านและเขียนไฟล์
  6. Error Handling - การจัดการข้อผิดพลาดด้วย try-except
  7. Algorithm Design - การออกแบบขั้นตอนการแก้ปัญหา

🔑 สิ่งที่เรียนรู้ (Key Learnings)

1. Computational Thinking

  • Decomposition: แบ่งปัญหาใหญ่ให้เป็นปัญหาย่อยๆ
  • Pattern Recognition: มองเห็นรูปแบบที่ซ้ำกันในปัญหา
  • Abstraction: แยกส่วนสำคัญออกจากรายละเอียดที่ไม่จำเป็น
  • Algorithm Design: เขียนขั้นตอนการแก้ปัญหาอย่างเป็นระบบ

2. Control Flow Mastery

  • Conditional Statements: การใช้ if, elif, else เพื่อตัดสินใจ
  • For Loops: การวนซ้ำจำนวนที่แน่นอน (Iteration)
  • While Loops: การวนซ้ำตามเงื่อนไข (Condition-based)
  • Nested Loops: การใช้ Loop ซ้อน Loop เพื่อแก้ปัญหาซับซ้อน

3. Data Structures in Python

  • Lists: เก็บข้อมูลเป็นลำดับ (Ordered Collection) - [1, 2, 3]
  • Dictionaries: เก็บข้อมูลแบบ Key-Value - {"name": "John", "age": 20}
  • Tuples: ข้อมูลที่ไม่เปลี่ยนแปลง (Immutable) - (x, y)
  • Sets: ข้อมูลที่ไม่ซ้ำกัน (Unique Collection) - {1, 2, 3}

4. Functions & Modular Programming

  • Function Definition: การสร้างฟังก์ชันด้วย def
  • Parameters & Arguments: การส่งค่าเข้าฟังก์ชัน
  • Return Values: การส่งค่ากลับจากฟังก์ชัน
  • Scope: ขอบเขตของตัวแปร (Local vs Global)

5. Problem Solving Skills

  • Input Validation: การตรวจสอบข้อมูลที่ผู้ใช้ป้อน
  • Edge Cases: การจัดการกรณีพิเศษ (เช่น input เป็น 0, ติดลบ)
  • Debugging: การหาและแก้ไข Bug ในโค้ด
  • Code Optimization: การปรับปรุงโค้ดให้ทำงานเร็วขึ้น

📂 โครงสร้างภายใน (Repository Structure)

Computer-Programming/
├── README.md                 ← ไฟล์นี้
├── lab/                      ← Lab ปฏิบัติการและแบบทดสอบ
│   ├── Practical Test 1/     → แบบสอบกลางภาค (Logic & Loops)
│   └── Practical Test 2/     → แบบสอบปลายภาค (Functions & Data Structures)
└── assignment/               ← งานที่มอบหมาย (8 ชุด)
    ├── assignment 1/         → พื้นฐาน Python (Variables, I/O)
    ├── assignment 2/         → Control Flow (if-else)
    ├── assignment 3/         → Loops (for, while)
    ├── assignment 4/         → Lists (Array Operations)
    ├── assignment 5/         → Functions
    ├── assignment 6/         → Dictionaries
    ├── assignment 7/         → File I/O
    └── assignment 8/         → Integration (รวมความรู้ทั้งหมด)

📚 Lab & Practical Tests

🧪 Practical Tests (สอบปฏิบัติ)

Practical Test 1 - กลางภาค

หัวข้อที่สอบ:

  • การรับและแสดงผล Input/Output
  • การใช้ Conditional Statements (if-else)
  • การคำนวณทางคณิตศาสตร์
  • การแปลงหน่วย

ตัวอย่างโจทย์:

  • เปรียบเทียบเลข 2 จำนวนว่าตัวไหนมากกว่า
  • แปลงหน่วยจากเซนติเมตรเป็นฟุต

Practical Test 2 - ปลายภาค

หัวข้อที่สอบ:

  • การใช้ Loops (for, while)
  • การจัดการ Lists และ Dictionaries
  • การสร้าง Pattern ด้วย Loop
  • Functions และการเรียกใช้งาน

ตัวอย่างโจทย์:

  • หาผลรวมของเลขคู่ตั้งแต่ 1-N
  • จัดการข้อมูลนักเรียนด้วย Dictionary
  • พิมพ์รูปทรงเรขาคณิตด้วย Loop

📝 Assignments (งานที่มอบหมาย)

Assignment 1 - Python Fundamentals 🟢

หัวข้อ: Variables, Data Types, Basic I/O, Type Conversion

  • แสดงข้อมูลนักศึกษา (รหัส, ชื่อ, จังหวัด)
  • คำนวณพื้นที่สามเหลี่ยมและสี่เหลี่ยม
  • ตรวจสอบชื่อตัวแปรที่ถูกต้อง
  • แสดงและแปลง Type ของตัวแปร

Assignment 2 - Variables & Math 🟢

หัวข้อ: Arithmetic Operations, Mathematical Calculations

  • การคำนวณทางคณิตศาสตร์
  • การใช้งานตัวแปรและนิพจน์
  • การแปลงหน่วย

Assignment 3 - Control Flow (if-else) 🟡

หัวข้อ: Conditional Statements, Comparison Operators

  • การตัดสินใจด้วย if-else
  • การเปรียบเทียบค่า
  • Nested if statements

Assignment 4 - Loops & Iteration 🟡

หัวข้อ: for loop, while loop, range(), Patterns

  • การวนซ้ำจำนวนที่แน่นอน
  • การวนซ้ำตามเงื่อนไข
  • การสร้าง Pattern
  • การใช้ break และ continue

Assignment 5 - List Operations 🟠

หัวข้อ: List Creation, Indexing, Methods

  • การสร้างและแก้ไข List
  • การเพิ่ม/ลบข้อมูล (append, remove)
  • การเข้าถึงข้อมูลด้วย Index
  • List Methods และ Functions

Assignment 6 - Advanced Lists 🟠

หัวข้อ: List Comprehension, Nested Lists

  • การจัดการ List ซับซ้อน
  • List ซ้อน List
  • การวน Loop ใน List

Assignment 7 - Dictionaries 🔴

หัวข้อ: Key-Value Pairs, Dictionary Methods

  • การสร้างและใช้งาน Dictionary
  • การเพิ่ม/ลบ/แก้ไขข้อมูล
  • การวน Loop ใน Dictionary

Assignment 8 - Integration 🔴

หัวข้อ: รวมความรู้ทั้งหมด

  • ใช้ Lists, Dictionaries, Loops ร่วมกัน
  • ออกแบบโปรแกรมที่ทำงานได้จริง
  • ฝึกการแก้ปัญหาแบบองค์รวม

🛠️ เครื่องมือที่ใช้

✅ Required

  • Python 3.x - ภาษาหลัก (แนะนำ Python 3.8+)
  • IDE/Editor:
    • VS Code + Python Extension (แนะนำ)
    • หรือ PyCharm (Community Edition ฟรี)
    • หรือ Jupyter Notebook (สำหรับทดลองโค้ด)

📦 Libraries ที่ใช้

ส่วนใหญ่ใช้ Built-in Libraries ไม่ต้องติดตั้งเพิ่ม:

  • math - คำนวณทางคณิตศาสตร์
  • random - สุ่มตัวเลข
  • os - จัดการไฟล์และโฟลเดอร์

🚀 วิธีการรัน (How to Run)

📋 Prerequisites

  1. ติดตั้ง Python:

    • Windows: Download จาก python.org
    • Mac: มีมาให้แล้ว หรือติดตั้งผ่าน Homebrew
    • Linux: sudo apt install python3
  2. ตรวจสอบว่าติดตั้งสำเร็จ:

    python --version
    # หรือ
    python3 --version

▶️ รันโปรแกรม

  1. เปิด Terminal/Command Prompt
  2. ไปที่โฟลเดอร์ที่มีไฟล์ .py
  3. รันด้วยคำสั่ง:
    python filename.py
    # หรือ
    python3 filename.py

ตัวอย่าง:

cd Computer-Programming/assignment/assignment\ 1/
python main.py

🔧 Troubleshooting

  • python ไม่ทำงาน: ลอง python3 แทน (บน Mac/Linux)
  • ไม่เจอคำสั่ง: ตรวจสอบว่าเพิ่ม Python ลใน PATH แล้ว
  • Error แปลกๆ: ตรวจสอบ Indentation (Python ใช้เว้นวรรคบังคับ)

📖 แนะนำสำหรับรุ่นน้อง

🎓 เริ่มต้นอย่างไร?

  1. ทำ Assignment ตามลำดับ: อย่าข้าม เพราะความรู้สะสมต่อกัน
  2. พิมพ์โค้ดเอง: อย่าแค่ Copy-Paste จะจำไม่ได้
  3. ทดลองเปลี่ยนค่า: ลองแก้โค้ดดูว่าถ้าเปลี่ยนจะเกิดอะไรขึ้น
  4. อ่าน Error Message: Python บอกว่าผิดตรงไหนชัดเจนมาก

💡 Tips & Best Practices

  • ใช้ชื่อตัวแปรที่มีความหมาย: age ดีกว่า x
  • เขียน Comment: อธิบายโค้ดที่ซับซ้อนด้วย #
  • ลอง Print ดู: ใช้ print() เพื่อดูค่าตัวแปรตอนรัน (Debugging ง่ายสุด)
  • ฝึกเขียนบ่อยๆ: การเขียนโค้ดเหมือนเล่นกีฬา ยิ่งฝึกยิ่งเก่ง
  • ใช้ PEP 8 Style: มาตรฐานการเขียน Python ที่ดูสวยงาม

📚 แหล่งเรียนรู้เพิ่มเติม

⚠️ สิ่งที่ควรหลีกเลี่ยง

  • ❌ อย่าจำแต่ Syntax ให้เข้าใจ Logic
  • ❌ อย่าเปิดหลายบทพร้อมกัน เรียนทีละบท
  • ❌ อย่า Copy Code จาก ChatGPT แล้วส่งเลย (เรียนไม่รู้เรื่อง)
  • ❌ อย่า Indent ผิด (Python จะ Error ทันที)

📄 License

โค้ดในโปรเจกต์นี้เป็นส่วนหนึ่งของการเรียนการสอนในรายวิชา COM 1305 Computer Programming


Happy Coding! 🐍💻

"Everyone should learn to code. It teaches you how to think." - Steve Jobs