ยกกำลังแบบ Recursion

📋 โจทย์

รับฐาน (base) และเลขชี้กำลัง (exp) (บรรทัดเดียว คั่นเว้นวรรค) แสดง base^exp โดยใช้ recursion

⚠️ ข้อจำกัด

1 ≤ base ≤ 100 0 ≤ exp ≤ 20

📝 ตัวอย่าง

ตัวอย่างที่ 1
Input:
2 10
Output:
1024
ตัวอย่างที่ 2
Input:
3 0
Output:
1
ตัวอย่างที่ 3
Input:
5 3
Output:
125
🔓 ดูเฉลย
def power(base, exp):
    if exp == 0:
        return 1
    return base * power(base, exp - 1)

b, e = map(int, input().split())
print(power(b, e))

💡 base case: exp=0 → return 1, recursive: base * power(base, exp-1)

🐍 main.py

กด Run เพื่อรันโค้ด หรือ ตรวจคำตอบ เพื่อตรวจ test cases