Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Roman Numeral Conversion
00:00
5 left

Roman Numeral Conversion

MediumPython

Problem

Write two functions: one that converts a number to a Roman numeral and another that converts a Roman numeral back to a number.

Implement int_to_roman(num) and roman_to_int(roman) for canonical Roman numerals from 1 through 3999. For grading, expose convert_roman(num, roman), which returns both results as {"int_to_roman": string, "roman_to_int": integer}.

Constraints

  • 1 <= num <= 3999
  • roman contains only the characters I, V, X, L, C, D, and M
  • roman is a canonical Roman numeral representing a value from 1 through 3999
  • The two input values are independent conversion inputs

Function Signature

def convert_roman(num, roman):
Interviewer

Your question is Roman Numeral Conversion. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.