🐕 Pet Breed Recommender

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

← All projects

📖 What is this project?

Pet Breed Recommender คือโปรแกรมแนะนำสายพันธุ์สัตว์เลี้ยง — บอกว่าอยากเลี้ยงแมว หมา หรือเต่า แล้วโปรแกรมจะสุ่มแนะนำสายพันธุ์จากคลังของแต่ละชนิดให้ เหมือนเปิดกล่องสุ่ม (นักเรียนตั้งชื่อฟังก์ชันว่า lootbox เลย!)

ถึงจะเป็นโปรแกรมสั้น ๆ แต่ครบองค์ประกอบสำคัญของการเขียนโปรแกรม: เก็บข้อมูลเป็น list แยกหมวด, สร้างฟังก์ชันที่รับพารามิเตอร์และคืนค่า, ใช้ if/elif เลือกเส้นทาง และประกอบข้อความด้วย f-string — เป็นตัวอย่างที่ดีมากของการเขียนโค้ดให้สั้นแต่ทำงานได้จริง

🧠 What they used from the Python course:
list — คลังสายพันธุ์ 3 หมวด def + พารามิเตอร์ — ฟังก์ชัน lootbox(choice) return ค่าออกจากฟังก์ชัน random.choice — สุ่มไม่ซ้ำเดิม if / elif เลือกคลังตามชนิดสัตว์ f-string ประกอบข้อความคำตอบ .lower() รองรับพิมพ์เล็กพิมพ์ใหญ่

🕹️ 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

cat = ["Maine Coon", "Sphynx", "Bengal"]#กำหนดค่าให้กับตัวแปล"cat"
dog = ["Doberman", "Shiba Inu", "Scottish Terrier"]#กำหนดค่าให้กับตัวแปล"dog"
turtle = ["Alligator Snapping Turtle", "Indian Star Tortoise", "Eastern Box Turtle"]#กำหนดค่าให้กับตัวแปล"turtle"

def lootbox(choice):#กำหนด function lootbox
    if choice == "cat":
        return random.choice(cat)
    elif choice == "dog":
        return random.choice(dog)
    elif choice == "turtle":
        return random.choice(turtle)

choice = input("What pet would like i'll recommend you a breed(cat, dog, turtle): ").lower()#รับค่าจากผู้ใช้
print(f"oh ill would recommend the {lootbox(choice)}")#ส่งค่าคืนผู้ใช้(แนะนำพันธุ์สัตว์)
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.