เลขโรมัน (1-9)

📋 โจทย์

รับจำนวนเต็ม 1 ตัว ถ้าเป็น 1-9 แสดงเลขโรมัน (I, II, III, IV, V, VI, VII, VIII, IX) ถ้าเป็นจำนวนลบ แสดง "Error : Please input positive number" ถ้าเป็น 0 หรือ > 9 แสดง "Error : Out of range"

⚠️ ข้อจำกัด

-1,000 ≤ N ≤ 1,000

📝 ตัวอย่าง

ตัวอย่างที่ 1
Input:
3
Output:
III
ตัวอย่างที่ 2
Input:
-1
Output:
Error : Please input positive number
ตัวอย่างที่ 3
Input:
10
Output:
Error : Out of range
🔓 ดูเฉลย
n = int(input())
if n < 0:
    print("Error : Please input positive number")
elif n < 1 or n > 9:
    print("Error : Out of range")
else:
    roman = ["","I","II","III","IV","V","VI","VII","VIII","IX"]
    print(roman[n])

💡 ตรวจเงื่อนไขลบก่อน แล้วเงื่อนไขนอกช่วง สุดท้ายใช้ list lookup แปลงเป็นโรมัน

🐍 main.py

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