https://github.com/naemazam/roman-to-decimal-converter
Python based Roman to Decimal converter
https://github.com/naemazam/roman-to-decimal-converter
python3 roman-number-converter roman-numerals
Last synced: 7 months ago
JSON representation
Python based Roman to Decimal converter
- Host: GitHub
- URL: https://github.com/naemazam/roman-to-decimal-converter
- Owner: naemazam
- Created: 2021-11-20T17:08:45.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-20T17:34:09.000Z (almost 4 years ago)
- Last Synced: 2025-01-14T13:57:13.807Z (9 months ago)
- Topics: python3, roman-number-converter, roman-numerals
- Language: Python
- Homepage:
- Size: 2.93 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Roman to Decimal-converter
Python based Roman to Decimal converter
## Simple Knowledge
Roman numerals are a numeral system that originated in ancient Rome and remained the usual way of writing numbers throughout Europe well into the Late Middle Ages. Numbers in this system are represented by combinations of letters from the Latin alphabet.
The decimal numeral system is the standard system for denoting integer and non-integer numbers. It is the extension to non-integer numbers of the Hindu–Arabic numeral system. The way of denoting numbers in the decimal system is often referred to as decimal notation.
## Python Code
Copy code and test on Any Editor
```python
def encoder(num):
roman,s,decimal= ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"],"",[1000,900,500,400,100,90,50,40,10,9,5,4,1]
for i in range(13):
while num >= decimal[i]:
num -= decimal[i]
s += roman[i]
return sdef decoder(r):
k=r
if r=="":return "Don't leave the input blank"
roman,s= {"M":1000,"CM":900, "D":500, "CD":400, "C":100, "XC":90, "L":50, "XL":40, "X":10, "IX":9, "V":5, "IV":4, "I":1},0
while r!="":
if r[:2] in roman:a,r=r[:2],r[2:]
elif r[0] in roman:a,r=r[0],r[1:]
else: return "Enter proper Decimal/Roman number as input"
s+=roman[a]
return s if encoder(int(s))==k else "Not a valid Roman Numeral"
a=input()
try:print(encoder(int(a)))
except:print(decoder(a.upper()))
```## Contributing
Contributions are always welcome!