HSL25BH
出自 青少年追求卓越
於 2025年5月9日 (五) 19:21 由 Limingyu2007 (對話 | 貢獻) 所做的修訂
- 靖恩和佳恩 Python 程式設計課程,每週六 9:00-10:30。
- Pairing Khan Academy’s “Intro to Computer Science – Python” course with Thonny is a great way to combine the strengths of both platforms:
- Khan Academy: Teaches concepts interactively in a browser.
- Thonny: Lets students write, run, and debug code in a real Python environment.
目錄
Python Practice Worksheet
Here’s a printable student worksheet template you can use to help your students pair Khan Academy's Python course with Thonny. It's designed to guide reflection, practice, and code experimentation. 📝 Python Practice Worksheet Name: _____________________ Date: _______________ Lesson Topic: ___________________________________________ Khan Academy Unit/Lesson URL: ___________________________ 1️⃣ What I Learned ✍ Write 2–3 things you learned from today’s Khan Academy lesson. 2️⃣ Sample Code from Khan Academy ✍ Copy the code you practiced during the lesson. python 複製 編輯 # Paste your Khan Academy code here 3️⃣ My Modified Version in Thonny ✍ Edit, improve, or experiment with the code. python 複製 編輯 # Paste your modified code from Thonny here 4️⃣ What Happened When I Ran the Code? ✍ Describe what the program did and if it worked as expected. 5️⃣ What I Changed or Tried ✍ List 1–2 things you changed or added in Thonny (e.g., new variable, condition, or loop). 6️⃣ My Questions or Confusions ✍ Write down anything you didn’t understand or want to ask the teacher. ✅ Teacher Feedback (optional) 🧑🏫 __________________________________________________________ 🧑🏫 __________________________________________________________ 🧑🏫 __________________________________________________________
How to Pair Khan Academy with Thonny
🔗 How to Pair Khan Academy with Thonny 🧭 Step 1: Use Khan Academy to learn concepts Direct your students to follow lessons and complete exercises on https://www.khanacademy.org/computing/intro-to-python-fundamentals Encourage them to watch the videos, try the interactive tasks, and read the explanations 💻 Step 2: Recreate or expand activities in Thonny Once they complete a coding task on Khan Academy: Open Thonny Create a new file (e.g., my_program.py) Type out the same code from the Khan activity—or rewrite it in their own words Run and test the program in Thonny Experiment: Modify the code to explore new behavior For example: Change variable values Add print statements Add comments (#) to explain logic 🔄 Step 3: Reinforce learning with projects After each unit (e.g., variables, loops), assign a mini project in Thonny using what they just learned Examples: After “functions” → build a calculator After “loops” → print a triangle pattern 🧠 Benefits of This Pairing Khan Academy Thonny Interactive, guided lessons Real-world Python environment Auto-checking and hints Full control and debugging tools Ideal for concept introduction Ideal for hands-on practice ✏️ Suggested Routine for Your Students Watch Khan video + do the exercise Rewrite and expand the code in Thonny Save and share their .py file Add a reflection (what they learned or struggled with)
A Python program using database
Show me an example of a Python program using database. ChatGPT 說: Certainly! Here's a simple Python example that uses a SQLite database to: Create a table Insert data Retrieve and display it SQLite is a built-in database that comes with Python, so no installation is needed. 🗃️ Example: Python + SQLite (Contacts Database) import sqlite3 # Connect to (or create) a database file conn = sqlite3.connect("contacts.db") # Create a cursor to execute SQL commands cursor = conn.cursor() # 1️⃣ Create a table cursor.execute(''' CREATE TABLE IF NOT EXISTS contacts ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, phone TEXT NOT NULL ) ''') # 2️⃣ Insert data cursor.execute("INSERT INTO contacts (name, phone) VALUES (?, ?)", ("Alice", "123-4567")) cursor.execute("INSERT INTO contacts (name, phone) VALUES (?, ?)", ("Bob", "987-6543")) # 3️⃣ Commit changes to the database conn.commit() # 4️⃣ Retrieve and display data cursor.execute("SELECT * FROM contacts") rows = cursor.fetchall() for row in rows: print(f"ID: {row[0]}, Name: {row[1]}, Phone: {row[2]}") # 5️⃣ Close the connection conn.close() 🧾 Sample Output ID: 1, Name: Alice, Phone: 123-4567 ID: 2, Name: Bob, Phone: 987-6543 ✅ Key Features Uses Python’s built-in sqlite3 module Simple and local: creates a file called contacts.db Good for beginners learning CRUD operations (Create, Read, Update, Delete)
When to learn Flask
When people start learning Python, do they need to know or use Flask? ChatGPT 說: No, people do not need to learn Flask when they first start learning Python. 🎯 Why Flask Isn't Needed at the Start ✅ When you're just starting, focus on: Python syntax and data types (e.g., strings, numbers, lists) Control structures (if, for, while) Functions and loops Basic input/output File handling Optional: using Thonny or a simple IDE Example beginner programs: name = input("What is your name? ") print(f"Hello, {name}!") 🧱 When to Learn Flask You should start learning Flask after you've mastered the basics of Python and are ready to: Build web apps or online tools Handle user forms and input over the internet Connect Python to a front-end like HTML or JavaScript Work with databases or create REST APIs 🧠 Learning Path Suggestion Stage Focus Beginner Core Python (variables, loops, logic) Intermediate Functions, modules, file I/O, error handling Advanced OOP, libraries (e.g., requests, pandas) Web Development Flask, databases, HTML/CSS, APIs ✅ Summary Learn Flask only after you're comfortable with Python basics. If you're teaching teens or beginners, Flask can wait until they're building projects that require web interaction. Would you like a visual learning roadmap for Python leading to Flask?