Open the context
Choose the project folder and name the files or behavior involved.
Format an integer from 1 through 3999 as a canonical uppercase Roman numeral. Check subtractive forms such as 4 and 900, rejecting zero, out-of-range numbers and non-integers.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def roman_numeral(n):
if type(n) is not int or not 1 <= n <= 3999:
raise ValueError("roman.range")
values = [(1000,"M"),(900,"CM"),(500,"D"),(400,"CD"),
(100,"C"),(90,"XC"),(50,"L"),(40,"XL"),
(10,"X"),(9,"IX"),(5,"V"),(4,"IV"),(1,"I")]
parts = []
for value, symbol in values:
count, n = divmod(n, value)
parts.append(symbol * count)
return "".join(parts)The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.