🧪 Periodic Table Quiz

✍️ Coded line by line by Khemintra Chulakranta, age 16 💛 · See full profile and all works →

← All projects

📖 What is this project?

Periodic Table Quiz คือเกมฝึกท่องตารางธาตุ 36 ธาตุแรก นักเรียนเก็บชื่อธาตุกับสัญลักษณ์ทั้งหมดไว้ใน dictionary แล้วสุ่มถามทีละธาตุ ตอบถูกปุ๊บระบบจะตัดข้อนั้นออกจากคลังทันที เกมจึงวนถามเฉพาะข้อที่ยังตอบไม่ได้ จนกว่าจะครบทั้ง 36 ธาตุ — นี่คือเทคนิคเดียวกับที่แอปท่องศัพท์ระดับมืออาชีพใช้กัน

ที่น่าชมคือนักเรียนใช้ .capitalize() ปรับตัวพิมพ์คำตอบให้อัตโนมัติ (พิมพ์ fe หรือ FE ก็ผ่าน) และใช้รหัสสี ANSI ขีดเส้นใต้คำว่า CORRECT/WRONG ให้อ่านง่าย — เป็นการเอาวิชาเคมีมาผสมกับการเขียนโปรแกรมได้อย่างชาญฉลาด

🧠 What they used from the Python course:
dictionary — เก็บคู่ชื่อธาตุ↔สัญลักษณ์ทั้ง 36 ธาตุ random.choice — สุ่มข้อสอบไม่ให้เดาได้ def สร้างฟังก์ชันตรวจคำตอบ while loop — วนถามจนคลังข้อสอบว่าง .pop() — ตัดข้อที่ตอบถูกแล้วออก .capitalize() — ปรับตัวพิมพ์คำตอบให้อัตโนมัติ ANSI escape codes — ขีดเส้นใต้ข้อความในเทอร์มินัล บูรณาการวิชาเคมีเข้ากับโค้ด

🕹️ Try the real thing!

This is the real program, converted to run on the web with every rule kept exactly the same — type your answer and press Enter, just like running it in Python.

👨‍💻 The original Python source code (with the comments they wrote themselves)

import random
periodic = {'Hydrogen':'H','Helium':'He','Lithium':'Li',
'Beryllium':'Be','Boron':'B','Carbon':'C','Nitrogen':'N',
'Oxygen':'O','Fluorine':'F','Neon':'Ne','Sodium':'Na',
'Magnesium':'Mg','Aluminium':'Al','Silicon':'Si','Phosphorus':'P',
'Sulfur':'S','Chlorine':'Cl','Argon':'Ar','Potassium':'K',
'Calcium':'Ca','Scandium':'Sc','Titanium':'Ti','Vanadium':'V',
'Chromium':'Cr','Manganese':'Mn','Iron':'Fe','Cobalt':'Co',
'Nickel':'Ni','Copper':'Cu','Zinc':'Zn','Gallium':'Ga',
'Germanium':'Ge','Arsenic':'As','Selenium':'Se','Bromine':'Br',
'Krypton':'Kr'}

print("\033[4mPeriodic Table Atomic number 1-36\033[0m")

def scoring():
    if answer == periodic[e]:
        print('\033[4mCORRECT\033[0m')
        print('--------------------')
        periodic.pop(e)
    else:
        print('\033[4mWRONG\033[0m')
        print(periodic[e])
        print('--------------------')

while periodic != {}:
    element = random.choice(list(periodic.items()))
    e = element[0]
    print(e)
    answer = input('Short word for this element is...\n==> ').capitalize()
    scoring()

print('Well done you answered all 36 element')
Share on LINE
Want your child to build games like this?

Our Python course is taught live, one-on-one, and every child builds a real project of their own just like these.