Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm trying to create a python 3 program that prints numbers as Roman Numerals: Roman Numerals use letters to represent numbers. 1 is I 5

I'm trying to create a python 3 program that prints numbers as Roman Numerals:

Roman Numerals use letters to represent numbers.

1 is I

5 is V

10 is X

50 is L

100 is C

500 is D

1,000 is M

5,000 is v (really capital v with a line, but we can't print that)

10,000 is x (really capital x with a line)

Other numbers are made with a combination of these letters. For example, 3 is III.

Note: Numbers greater than 3,999 require symbols with lines over letters. We can't use these, so use lower case v for 5000 and x for 10000.

The first 10 numbers are

I

II (1+1=2)

III (1+1+1=3)

IV (5-1=4)

V

VI (5+1=6)

VII (5+2=7)

VIII (5+3=8)

IX (10-1=9)

X

This pattern repeats for larger numbers. For example to create 47, we need to figure out 40 first. 4 was IV, there are equivalent 1, 5, and 10 symbols for the tens place. We can determine that 40 is XL since X is 10 and L is 50. We then combine this with 7 from above to get XLVII. Every value can be broken down into this basic 1-9 pattern just using different symbols.

(1) Create a function roman(num, one, five, ten) that takes a number between 1 and 9. The function returns a string with the roman representation using the strings given for the one, five, and ten symbols. If a number outside the range is given return the empty string "".

For example, Executing roman(4,"X","L","C") should return "XL"

(2) Create a function roman_num(num) that takes a number between 1 and 9,999 and returns it as a Roman Numeral. Return an empty string outside the range. Use the function from the previous step.

For example, executing roman_num(47) should return "XLVII".

(3) Create a main program that asks users for a number and prints it as a Roman Numeral. The program should run until the user enters 0. Use the functions from the previous steps. Print "Bye." when you exit. Remember to use if name=="main".

Example execution trace:

Roman Number Generator. Enter 0 to quit.

Enter a number between 1 and 9,999:

1

Roman Numerals: I

Enter a number between 1 and 9,999:

2

Roman Numerals: II

Enter a number between 1 and 9,999:

3

Roman Numerals: III

Enter a number between 1 and 9,999:

9

Roman Numerals: IX

Enter a number between 1 and 9,999:

28

Roman Numerals: XXVIII

Enter a number between 1 and 9,999:

17

Roman Numerals: XVII

Enter a number between 1 and 9,999:

2017

Roman Numerals: MMXVII

Enter a number between 1 and 9,999:

0

Roman Numerals:

Bye.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions