🐱 Cheer Me Up · โปรแกรมให้กำลังใจ
✍️ เขียนโค้ดเองทุกบรรทัดโดย นักเรียน Nutpoom Sookkasem อายุ 16 ปี 💛 · ดูโปรไฟล์และผลงานทั้งหมด →
📖 ผลงานนี้คืออะไร?
Cheer Me Up คือโปรแกรมเล็ก ๆ ที่อบอุ่นหัวใจ — เปิดมาถามว่า “วันนี้เหนื่อยหรือเปล่า?” ถ้าตอบว่าใช่ จะให้เลือก 3 ทาง: อยากได้คำปลอบใจ อยากได้คำคมสร้างแรงบันดาลใจ (สุ่มจากคลัง 10 ประโยคที่นักเรียนคัดมาเอง) หรืออยากดูรูปแมวน่ารัก ๆ ซึ่งโปรแกรมจะสั่งเปิดเว็บเบราว์เซอร์ขึ้นมาให้เลย
ผลงานชิ้นนี้แสดงให้เห็นว่านักเรียนเข้าใจการใช้ webbrowser สั่งงานโปรแกรมอื่นจาก Python ได้ และที่สำคัญกว่านั้น — นักเรียนคิดถึงความรู้สึกของคนใช้ ไม่ใช่แค่เขียนโค้ดให้ทำงานได้ ซึ่งเป็นหัวใจของการออกแบบซอฟต์แวร์ที่ดี
🕹️ ลองเล่นของจริงเลย!
นี่คือโปรแกรมของนักเรียนแปลงมารันบนเว็บแบบเป๊ะ ๆ ทุกกติกา — พิมพ์คำตอบแล้วกด Enter เหมือนรันใน Python จริง
👨💻 โค้ด Python ต้นฉบับ (พร้อมคอมเมนต์ที่เจ้าของเขียนเอง)
import random
import webbrowser as wb
#ใส่ข้อมูลใส่ array
quotes = ["You didn’t come this far to stop now.", "Ignore the sheep. Be the lion.", "Flow like water. Adapt.", "No darkness, no stars.", "Small wins build empires.", "Big things start small.", "Pressure makes diamonds.", "Win or learn. No losing.", "Fear kills more dreams than failure.", "Legends are built, not born."]
cats = ["https://images.unsplash.com/photo-1529778873920-4da4926a72c2?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8Y3V0ZSUyMGNhdHxlbnwwfHwwfHw%3D&ixlib=rb-1.2.1&q=80&w=1000", "https://i.pinimg.com/originals/b6/a6/d5/b6a6d50de7eb36065b98ebd254d46cd5.jpg", "https://www.publicdomainpictures.net/pictures/160000/velka/mignon-petit-chaton.jpg", "https://tse3.mm.bing.net/th?id=OIP.X3mfeI7lW-x1NvHx8AZwAAHaHa&pid=Api"]
def inspri():#กำหนด function inspri
ins = random.choice(quotes)
return ins
def catpic():#กำหนด function catpic
cat = random.choice(cats)
return cat
a = input("Are you a bit own today?: ").lower()#ถามหาข้อมูลจากผู้ใช้
if a in ["yes", "y"]:#ตรวจสอบข้อมูลว่าได้รับค่า "yes" หรือ ค่า "y" มาหรือไม่
a = input("Do you want me to comfort you? or you want some insprirational quote? or just some cat pic would be fine?(1, 2, 3): ")#รับค่าจากผู้ใช้
if a == "1":#ตรวจสอบข้อมูลว่าได้รับค่า "1" มาหรือไม่
print("hope you get well soon bad thing will soon pass")
elif a == "2":#ตรวจสอบข้อมูลว่าได้รับค่า "2" มาหรือไม่
print(inspri())
elif a == "3":#ตรวจสอบข้อมูลว่าได้รับค่า "3" มาหรือไม่
wb.open(catpic())
else:
print("well see you later man")
คอร์ส Python ของเราสอนสดตัวต่อตัว เด็ก ๆ ได้ทำโปรเจ็คจริงของตัวเองแบบนี้ทุกคนค่ะ