Roman Number Generator. Enter 0 to quit. Enter a number between 1 and 9,999 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: 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: Roman Numerals: Bye.
Note: Numbers greater then 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": so ZyBooks can test your functions.
Here is an example execution trace.
This code is for Python!
![Roman Number Generator. Enter 0 to quit.
Enter a number between 1 and 9,999
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:
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:
Roman Numerals:
Bye.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F7003d56d-66b3-46c0-8a42-c29b64f3c145%2Fd97170c5-c874-455d-b48b-316376648417%2Fixlr7z.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 10 steps with 8 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)