forked from devAmoghS/Python-Interview-Problems-for-Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Amogh Singhal
authored
Nov 29, 2020
1 parent
e8b89a9
commit b72f0bd
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Write a program to convert interger to Roman Representation | ||
def convertIntegerToRomanNum(inputNumber): | ||
|
||
number_list = [ | ||
1000, 900, 500, 400, | ||
100, 90, 50, 40, | ||
10, 9, 5, 4, | ||
1 | ||
] | ||
|
||
symbol_list = [ | ||
'M', 'CM', 'D', 'CD', | ||
'C', 'XC', 'L', 'XL', | ||
'X', 'IX', 'V', 'IV', | ||
'I' | ||
] | ||
|
||
result_str = '' | ||
i = 0 | ||
|
||
while inputNumber > 0: | ||
for _ in range(inputNumber//number_list[i]): | ||
result_str = result_str + symbol_list[i] | ||
inputNumber = inputNumber - number_list[i] | ||
i = i + 1 | ||
return result_str | ||
|
||
roman = convertIntegerToRomanNum(289) | ||
print(roman) |